Express - Programmatically Add Select, and set Options List

Hey so I’m trying to figure out the correct steps for setting the Options List when adding an Attribute of type Select to an Express Object I’m building Programmatically… and falling on my face trying to figure it out… Can anyone help me please? This is what I have so far

        $object = Express::buildObject('test1', 'test1', 'Test1');
        $object->addAttribute('user_selector', 'Owner User', 'test_owner');
        $settings = new \Concrete\Core\Entity\Attribute\Key\Settings\SelectSettings();
        $list = ['test1', 'test2'];
        $optionList = new \Concrete\Core\Entity\Attribute\Value\Value\SelectValueOptionList();
        $object->addAttribute('select', 'Test Select', 'test_select', $settings);

I’ve just wasted so many hours trying to figure out how to add/edit/remove or whatever options for this, and I really think I need help.


I think you’re using setOptions in a wrong way.

$list = ['test1', 'test2'];
$optionList = new \Concrete\Core\Entity\Attribute\Value\Value\SelectValueOptionList();
foreach ($list as $i => $value) {
    $option = new \Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption();
1 Like

WOOO THIS WORKED TOO! And yeah, I know I was using it in a wrong way, but I couldn’t tell how I should use it, hah! Thanks again! :smiley: