Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MultiSelectConfigOption.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  const FRONTEND_WIZARD_CHECKBOX = 'checkbox';
17  const FRONTEND_WIZARD_MULTISELECT = 'multiselect';
21  private $selectOptions;
22 
35  public function __construct(
36  $name,
37  $frontendType,
38  array $selectOptions,
39  $configPath,
40  $description = '',
41  array $defaultValue = [],
42  $shortCut = null
43  ) {
44  if ($frontendType != self::FRONTEND_WIZARD_MULTISELECT && $frontendType != self::FRONTEND_WIZARD_CHECKBOX) {
45  throw new \InvalidArgumentException(
46  "Frontend input type has to be 'multiselect', 'textarea' or 'checkbox'."
47  );
48  }
49  if (!$selectOptions) {
50  throw new \InvalidArgumentException('Select options can\'t be empty.');
51  }
52  $this->selectOptions = $selectOptions;
53  parent::__construct(
54  $name,
55  $frontendType,
56  self::VALUE_REQUIRED | self::VALUE_IS_ARRAY,
57  $configPath,
59  $defaultValue,
60  $shortCut
61  );
62  }
63 
69  public function getSelectOptions()
70  {
71  return $this->selectOptions;
72  }
73 
81  public function validate($data)
82  {
83  if (is_array($data)) {
84  foreach ($data as $value) {
85  if (!in_array($value, $this->getSelectOptions())) {
86  throw new \InvalidArgumentException(
87  "Value specified for '{$this->getName()}' is not supported: '{$value}'"
88  );
89  }
90  }
91  }
92  parent::validate($data);
93  }
94 }
$value
Definition: gender.phtml:16
__construct( $name, $frontendType, array $selectOptions, $configPath, $description='', array $defaultValue=[], $shortCut=null)
$selectOptions
if(!isset($_GET['name'])) $name
Definition: log.php:14