- /**
- * {@inheritdoc}
- * @return array Format: array(array('value' => <value>, 'label' => '<label>'), ...)
- * @throws \InvalidArgumentException
- * @throws \UnexpectedValueException
- */
- public function evaluate(array $data)
- {
- if (!isset($data['model'])) {
- throw new \InvalidArgumentException('Options source model class is missing.');
- }
- $modelClass = $data['model'];
- $modelInstance = $this->objectManager->get($modelClass);
- if (!$modelInstance instanceof \Magento\Framework\Data\OptionSourceInterface) {
- throw new \UnexpectedValueException(
- sprintf("Instance of the options source model is expected, got %s instead.", get_class($modelInstance))
- );
- }
- $result = [];
- foreach ($modelInstance->toOptionArray() as $value => $label) {
- if (is_array($label)) {
- $result[] = $label;
- } else {
- $result[] = ['value' => $value, 'label' => $label];
- }
- }
- return $result;
- }