Concrete5 5.6.x - Setting Attribute Type Associations programmatically in a package controller

时间:2015-10-30 22:31:07

标签: php model-view-controller concrete5

I'm setting up a package for Concrete5 5.6.x that adds a bunch of User Attributes on install. One of them uses the image/file attribute that comes with Concrete5. When you install Concrete5 it does not add the image/file attribute type to User Attributes by default (see my screenshot below). So when my package goes to add this new attribute it won't install because it's not available there. It doesn't error out, it just does nothing.

In the dashboard I can go in and check boxes to make it available: Attribute Type Associations in the Dashboard

It's not realistic to tell people to do that first before installing the package. There must be a way to do it programmatically but I can't find anything in the forums or anywhere.

Here's the code for the controller function as it is now:

private function addUsersAttr($pkg){
 Loader::model('user_attributes');    

$img_att = AttributeType::getByHandle('image_file');

// Set to User
    $user_att_coll = AttributeKeyCategory::getByHandle('user'); 
    if (!$user_att_coll->allowAttributeSets()) {
        $user_att_coll->setAllowAttributeSets(AttributeKeyCategory::ASET_ALLOW_SINGLE);
     }

     // User Attribute Set & Attributes
    $user_att_set = AttributeSet::getByHandle('author_info');
    if(!is_object($user_att_set)){
            $user_att_set = $user_att_coll->addSet('author_info', t('Author Info'),$pkg);
    }

$ai_portrait=CollectionAttributeKey::getByHandle('ui_portrait'); 
    if( !is_object($ai_portrait) ) {
        CollectionAttributeKey::add($img_att,
        array('akHandle' => 'ui_portrait',
        'akName' => t('Portrait Image'),
        'akIsSearchable' => false, 
        'uakProfileEdit' => true, 
        'uakProfileEditRequired'=> false, 
        'uakRegisterEdit' => false, 
        'uakProfileEditRequired'=>false,
        'displayOrder'=> '9'
        ), $pkg)->setAttributeSet($user_att_set); 
    }

}

Thanks

1 个答案:

答案 0 :(得分:0)

在您的控制器中,您使用的是CollectionAttributeKey,但在您的语句中,您说您正在尝试添加用户属性。如果要添加用户属性,则需要使用UserAttributeKey。