Programmatically set select values
Permalink
I am building a page importer and I have an "Option List" page attribute that allows for multiple values to be selected, and I am attempting to programmatically generate a page with the correct options selected. The importer provides a list of values that need to all be selected, so I am trying to figure out how to select multiple option based their value for the page attribute.
I am using Concrete5.8.3.2.
I believe that the syntax is wrong inside the loop where I am checking that the option value exists, but I am not sure what the correct code would be. Any help would be appreciated. Thanks!
I am using Concrete5.8.3.2.
use Core; use Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey; use Concrete\Core\Entity\Attribute\Value\Value\SelectValue; use Concrete\Core\Entity\Attribute\Value\Value\SelectValueOption as SelectAttributeTypeOption; // Get the select list - Options are 'Category One', 'Category Two', 'Category Three', 'Category Four', and 'Category Five' $cak = CollectionAttributeKey::getByHandle('categories'); // Sample array of options that I want to select for this page $optionsArray = array( 'Category One', 'Category Two', 'Category Four' ); // Create an array to hold the option value objects $optionValueObjArray = array(); // Loop through all the desired options in the array
Viewing 15 lines of 29 lines. View entire code block.
I believe that the syntax is wrong inside the loop where I am checking that the option value exists, but I am not sure what the correct code would be. Any help would be appreciated. Thanks!
Here is the code in case anyone else can use it.