Installing attributes from package controller upgrade
Permalink 1 user found helpfulI've modified the package controller by Core77https://github.com/core77/foundation_sites...
Everything works on install but I would like to be able to add attributes and page types within a new version of the package.
Can anyone help point me in the right direction?
Am I using the incorrect function to do this?
public function upgrade() { parent::upgrade(); $pkg = parent::getByHandle('custom_pkg'); .... $this->installPageAttributes($pkg); } private function installPageAttributes($pkg) { $cakc = Category::getByHandle('collection'); $cakc->setAllowAttributeSets(Category::ASET_ALLOW_SINGLE); $fas = $cakc->addSet( 'custom_collection', t('Page Attributes'), $pkg); //add boolean attributes $bp_boolean = CollectionKey::getByHandle('secondary_navigation');
Thank you for your help
In its current state, no errors are displayed and the Page Attribute does not exist.
I can run the update_addon command, once run it does not display a confirmation message but it does refresh the page displaying the following 'No updates for your add-ons are available.' (I'm not sure a confirmation message appears if the upgrade is successful?)
I notice that I can install AttributesSets, they appear in the DB after I run the update but the Attributes don't? if that makes sense.
so I'm using the getByHandle to grab the package object, then pass that into the Attribute functions.
The Page attribute gets the attribute category from the AttributeKeyCategories table (collection)
$cakc->setAllowAttributeSets(Category::ASET_ALLOW_SINGLE);
Then prevents the attribute from appearing in multiple sets (I only want this set to appear in the page)
$bp_boolean = CollectionKey::getByHandle('secondary_navigation');
if (!$bp_boolean instanceof CollectionKey) {
$bp_boolean = CollectionKey::add('boolean', array(
'akHandle' => 'secondary_navigation',
'akName' => t('Secondary Navigation'),
'akIsSearchable' => true,
'akIsSearchableIndexed' => true), $pkg)->setAttributeSet($fas);
}
Then it should be checking to see if the page attribute exists and if not create the attribute, also assigning it to the set created above (Page Attributes)
I'm running a couple of other functions within the upgrade to create page types/templates but currently the one I appear to be having issues with is just the attribute creation (when run via upgrade)
$fas = $cakc->addSet( 'custom_collection', t('Custom Page Attributes'), $pkg);
Does anyone know if its possible to check for an attribute set first before adding it, I could only see a way to grab the attributeKey/Category handles and not the set
<?php namespace Concrete\Controller\SinglePage\Dashboard\Extend; use \Concrete\Core\Page\Controller\DashboardPageController; use TaskPermission; use Package; use Marketplace; use \Concrete\Core\Marketplace\RemoteItem as MarketplaceRemoteItem; use Localization; use Loader; use Config; use Exception; class Update extends DashboardPageController { public function on_start() { $this->error = Loader::helper('validation/error'); }
$fas = AttributeSet::getByHandle('ubisense_collection');
use \Concrete\Core\Attribute\Set as AttributeSet; //then $cas = AttributeSet::getByHandle('custom_collection'); if (!$cas instanceof AttributeSet) { ... }
Thanks for your help.
If you are not getting any errors but the package upgrade seems to not run you code it's possible that it is erroring trying to add a Page Attribute Set that is already there.