Create Attribute Set on Package Install

I have figured out how to create Attributes on Package install:

$attr = CollectionAttributeKey::getByHandle('exclude_subpages_from_nav');
    if( !$attr || !intval($attr->getAttributeKeyID()) ) {
       $attr = CollectionAttributeKey::add('boolean',array('akHandle'=>'exclude_subpages_from_nav','akName'=>t('Exclude Subpages from Nav'),'akIsSearchable'=>false,'asID'=>2),$pkg);

But, I am also trying to figure out how to create an Attribute Set on Package install... This functionality doesn't seem to exist (looking through the file 'concrete/core/models/attribute/set.php)

Am I not seeing something? Or is this just the way it is?

View Replies: View Best Answer
joemc replied on at Permalink Best Answer Reply
Nevermind. Found the answer here:

I did have to make one modification, though.

I could not add the attribute set directly after creating the attribute as shown in the link. I had to create the attribute first and have it save as an object variable, and then add it to a set.

$attr = CollectionAttributeKey::add('number',$args,$pkg);
nickcardoso replied on at Permalink Reply
That's great, but how do you actually create the set?

You have $gallerySet referenced but you haven't created it. Is it possible programatically?
shahroq replied on at Permalink Reply
//first create set:
$eaku = AttributeKeyCategory::getByHandle('collection');
$set = $eaku->addSet('my_set',t('My Set'),$pkg, 0);
$asID = $set->asID; 
//now create attributes under the set:
$key = CollectionAttributeKey::getByHandle('my_attr');
if (!$key || !intval($key->getAttributeKeyID())) {
   $attr_type = AttributeType::getByHandle('textarea');
   $desc =   array ( 'akHandle' => 'my_attr', 
               'akName'=> t('My Attribute'), 
               'asID' => $asID,
               'akTextareaDisplayMode' => 'text'
   $key = CollectionAttributeKey::add(   $attr_type, $desc , $pkg);