C5-BoilerplatePackageController
C5-BoilerplatePackageController copied to clipboard
Add Select Attributes Values
We've been implementing your controller methods - thank you. I've been trying to add select attribute values programmatically:
public function installSelect($pkg) {
// add a new set to page attr
$selectSet = $this->addAttributeSet('collection', 'my_selects', 'Selects', $pkg);
// set a new page attr key object
$collectionKey = new CollectionKey;
// create a select page attribute and add to the set
$selectAttr = $this->addAttribute('my_new_select', 'My New Select', 'select', $collectionKey, $selectSet, $pkg, true);
$optionValues = array('value1', 'value2', 'value3', 'value4');
$options = array();
$displayOrder = 0;
$list = new SelectValueOptionList();
foreach($optionValues as $value) {
$opt = new SelectValueOption();
$opt->setSelectAttributeOptionValue($value);
$opt->setDisplayOrder($displayOrder);
//$opt->setOptionList($list);
$options[] = $opt;
$displayOrder++;
}
$type = $selectAttr->getController()->getAttributeKey()->getAttributeKeySettings();
$list->setOptions($options);
$type->setOptionList($list);
}
But can't seem to apply the Option List in atSelectOptions
.avSelectOptionListID
I wonder if you have had any luck in this area?
I remember having major issues with how selects were done in the underlying C5 codebase, and was working on that a couple years ago, but I have not honestly delved into it lately, but I hope to get into it again soon. I'm happy this boilerplate has helped. I just wanted an organized way of doing things.
Wait, are you getting an error, or is it just failing silently?
And on a cursory overview, not having checked the docs (so please let me be boneheaded for a moment), why don't you just do $selectAttr->setOptionList($list);
?
I will have to delve further into it, but it seems that you should be setting it on the select attr itself.
I'll try and take a look next time i'm in concrete5. :/
avSelectOptionListID
is referenced in the atSelectOptions
table too so I'd been trying to set it on the option itself (commented out above), but yeah I see it's in atSelectSettings
too.
Thanks