Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Select.php
Go to the documentation of this file.
1 <?php
9 
12 
13 class Select extends AbstractData
14 {
19  {
20  return $this->_getRequestValue($request);
21  }
22 
26  public function validateValue($value)
27  {
28  $errors = [];
29  $attribute = $this->getAttribute();
30  $label = __($attribute->getStoreLabel());
31 
32  if ($value === false) {
33  // try to load original value and validate it
35  }
36 
37  if ($attribute->isRequired() && empty($value) && $value !== '0') {
38  $errors[] = __('"%1" is a required value.', $label);
39  }
40 
41  if (!$errors && !$attribute->isRequired() && empty($value)) {
42  return true;
43  }
44 
45  if (count($errors) == 0) {
46  return true;
47  }
48 
49  return $errors;
50  }
51 
55  public function compactValue($value)
56  {
57  return $value;
58  }
59 
63  public function restoreValue($value)
64  {
65  return $this->compactValue($value);
66  }
67 
74  protected function _getOptionText($value)
75  {
76  foreach ($this->getAttribute()->getOptions() as $option) {
77  if ($option->getValue() == $value && !is_bool($value)) {
78  return $option->getLabel();
79  }
80  }
81  return '';
82  }
83 
91  {
94  $output = $value;
95  } elseif ($value != '') {
96  $output = $this->_getOptionText($value);
97  } else {
98  $output = '';
99  }
100 
101  return $output;
102  }
103 }
extractValue(RequestInterface $request)
Definition: Select.php:18
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
_getRequestValue(\Magento\Framework\App\RequestInterface $request)
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16
$format
Definition: list.phtml:12
$errors
Definition: overview.phtml:9
outputValue($format=ElementFactory::OUTPUT_FORMAT_TEXT)
Definition: Select.php:90