Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractOptionsField.php
Go to the documentation of this file.
1 <?php
7 
10 
15 abstract class AbstractOptionsField extends AbstractElement
16 {
21  protected $options;
22 
31  public function __construct(
33  $options = null,
34  array $components = [],
35  array $data = []
36  ) {
37  $this->options = $options;
38  parent::__construct($context, $components, $data);
39  }
40 
47  public function prepare()
48  {
49  $config = $this->getData('config');
50  if (isset($this->options)) {
51  if (!isset($config['options'])) {
52  $config['options'] = [];
53  }
54  if ($this->options instanceof OptionSourceInterface) {
55  $options = $this->options->toOptionArray();
56  } else {
57  $options = array_values($this->options);
58  }
59  if (empty($config['rawOptions'])) {
61  }
62  $config['options'] = array_values(array_merge_recursive($config['options'], $options));
63  }
64  $this->setData('config', (array)$config);
65  parent::prepare();
66  }
67 
76  abstract public function getIsSelected($optionValue);
77 
85  protected function convertOptionsValueToString(array $options)
86  {
87  array_walk($options, function (&$value) {
88  if (isset($value['value']) && is_scalar($value['value'])) {
89  $value['value'] = (string)$value['value'];
90  }
91  });
92  return $options;
93  }
94 }
__construct(ContextInterface $context, $options=null, array $components=[], array $data=[])
$config
Definition: fraud_order.php:17
$value
Definition: gender.phtml:16