dongshi9526 2015-10-30 22:31
浏览 34

Concrete5 5.6.x - 在程序包控制器中以编程方式设置属性类型关联

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条回答 默认 最新

  • duanmeng9336 2016-06-06 15:46
    关注

    In your controller you are using CollectionAttributeKey but in your statement you said you are trying to add a User Attribute. If you want to add a User Attribute you need to use UserAttributeKey.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程