Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Select Attributes Values #2

Open
lewismcarey opened this issue Apr 26, 2017 · 3 comments
Open

Add Select Attributes Values #2

lewismcarey opened this issue Apr 26, 2017 · 3 comments

Comments

@lewismcarey
Copy link

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants