Counting "Option List" Express Attribute Type Selections

I want to count how many Options were selected for each Express Entry for a specific Attribute that is “Option List” type. It seems to exist as “object” data type in PHP and is not “Countable”. And my google-fu has not turned up some useful way to do this.

The Option List is set to multi-select, so 0, 1,…infinity, I want to count how many options were selected for each Express Entry.

What method have you folks found to gracefully do this?

@BloodyIron, assuming you an Express Data Object with a handle of bicycle and that object has an Option List attribute with a handle of color, you can get a count of the selected colors like this:

// get the Express entity
/* @var Concrete\Core\Entity\Express\Entity $entity */
$entity = Express::getObjectByHandle('bicycle');

// get the first entry
/* @var Concrete\Core\Entity\Express\Entry $entry */
$entry = (new Concrete\Core\Express\EntryList($entity))->getResults()[0];

// get the attribute value object
/* @Concrete\Core\Entity\Attribute\Value\Value\SelectValue $colors*/
$colors = $entry->getColor();

// get the selected values
$selectedColors = $colors->getOptions()

$n = count($selectedColors);
1 Like