Creating broken file attribute keys

Using version 9.1.1

I’m creating attribute keys and adding them to a set using this code:

if (!is_object($category->getByHandle($handle))) {
$key = new PageKey();
$key->setAttributeKeyHandle($handle);
$key->setAttributeKeyName($name);
$key->setIsAttributeKeySearchable($searcheable);
$category->add($type, $key, null, $pkg);
$setManager->addKey($fileSet, $key);
}

This seems to work. If I go to the file manager and click Attributes in the sidebar all of my attributes are there in the correct attribute set but when I click any of them I get the following error: Concrete\Controller\Element\Attribute\EditKey::__construct(): Argument #1 ($key) must be of type Concrete\Core\Attribute\AttributeKeyInterface, null given

Also, FileAttributeKey::getByHandle(‘handle_name’) returns null even when using the handle that I used to create the attribute key.

I have no idea what’s going wrong. I feel like the documentation is incredibly incomplete and outdated.

I’ll have engineering take a look. Can you tell me what version of PHP you are running?

On the docs site, mark the thumbs down on any pages you think need some updates, that will help prioritize. If you have any suggestions for docs to be written list them here too.

Here’s a working example from my Nav Target Attribute package controller for a collection attribute. There may be other things, but off the bat I notice you’re using pageKey(). I believe fileKey() is what you’re looking for…

$category = $this->app->make(CategoryService::class)->getByHandle('collection');
$cat = $category->getController();
$ak = $cat->getAttributeKeyByHandle('nav_target');
if (!is_object($ak)) {
	$pk = new PageKey();
	$pk->setAttributeKeyName('Nav Target');
	$pk->setAttributeKeyHandle('nav_target');
	$pk->setIsAttributeKeySearchable(true);
	$pk->setAttributeKeySettings(['akHideNoneOption', 'true']);
	$pk = $cat->add('select', $pk, $this->makeSettings(['_self', '_blank', '_parent', '_top']) , $pkg);
	//$this->addToSet($pk, 'navigation');
}

Thanks. Turns out it was a stupid mistake where I was using the PageKey instead of the FileKey class. However, adding a page key to a file category should have thrown an error.

As for improvements in the docs, you really shouldn’t be saying that using the CIF xml format is the easiest way of doing things when you don’t provide any meaningful documentation on the CIF format. Every example you have on doing anything programmatically that can be done using CIF should include documentation on how to do it with CIF. I thought I would try using the migration tool package so I could create things in the admin and export them to CIF to see how to do it but the package would not install. So maybe fix that as well.

I tried following the docs on using Bedrock. The docs might be fine but the bedrock npm install doesn’t work because of bad dependencies.

I also don’t see docs on how to add data to page or file attribute keys. Specifically, how do I add tags? Maybe the info is in the docs but I don’t see where it would be. I’ll be figuring that out next.