cryophallion / C5-BoilerplatePackageController

Boilerplate Controller for Packages
23 stars 8 forks source link

Add Select Attributes Values #2

Open lewismcarey opened 7 years ago

lewismcarey commented 7 years ago

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?

cryophallion commented 7 years ago

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.

cryophallion commented 7 years ago

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.

lewismcarey commented 7 years ago

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