How to create custom attribute using controller.php

Permalink
Hello,

I want to create is_featured checkbox attribute from controller.php and also want to create "background image" with image attribute.. also from controller.php

 
hutman replied on at Permalink Best Answer Reply
hutman
You should be able to do it with this

$is_featured = CollectionAttributeKey::getByHandle('is_featured');
if (!$is_featured instanceof CollectionAttributeKey) {
   $is_featured = CollectionAttributeKey::add("boolean", array(
      'akHandle' => 'is_featured',
      'akName' => t('Is Featured'),
      'akIsSearchable' => true,
      'akIsSearchableIndexed' => true), $pkg);
}
$photo = CollectionAttributeKey::getByHandle('photo');
if (!$photo instanceof CollectionAttributeKey) {
   $photo = CollectionAttributeKey::add("image_file", array(
      'akHandle' => 'photo',
      'akName' => t('Photo')), $pkg);
}


If you are working with 5.7 you will need these at the top of the controller I believe

use \Concrete\Core\Attribute\Type as AttributeType;
use CollectionAttributeKey;
psd2concrete5 replied on at Permalink Reply
Thanks Hutman,

It works for me.