If you have an attribute type in a package you need to do a little additional work in the install routine to get it registered fully with the system.

/* We install the attribute... */<br></br>
$at = AttributeType::add('country', 'Country', $pkg);<br></br>
/* then we associate with collections and users. */<br></br>
foreach (array('collection', 'user') as $c) {<br></br>
    $cat = AttributeKeyCategory::getByHandle($c);<br></br>

If you also want the attribute associated with files then add ‘file’ to the collections above.

Following the above the attribute will be available in the Dashboard / Page & Themes / Attributes page to be added as a page attribute.

If you want to add a page attribute at the same time as the attribute then the following code can be used (assuming it follows on directly from the above)


$data = array('akHandle' => 'my_attribute,

'akName' => 'My Attribute',

'akIsSearchable' => true,

'akIsSearchableIndexed' => true);

$att = CollectionAttributeKey::add($at, $data, $pkg);


Of course, you may also want to add this attribute you have just created to an attribute set, so you can also do this (once again assuming continuation of code from the above)

$aset = AttributeSet::getByHandle('navigation');<br></br>

Hopefully this can help others avoid spending the time it took me to figure this out 🙂