studioespresso/craft-exporter

View on GitHub
src/fields/MultiOptionsFieldParser.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace studioespresso\exporter\fields;

class MultiOptionsFieldParser extends OptionsFieldParser
{
    public function getValue($element, $field)
    {
        $selected = [];
        $property = $field['property'] ?? 'value';

        foreach ($element->getFieldValue($field['handle'])->getOptions() as $option) {
            if ($option->selected) {
                $selected[] = $option->$property;
            }
        }
        if ($selected) {
            return implode(', ', $selected);
        }

        return null;
    }
}