Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Multiselect.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class Multiselect extends \Magento\Eav\Model\Attribute\Data\Select
16 {
24  {
25  $values = $this->_getRequestValue($request);
26  if ($values !== false && !is_array($values)) {
27  $values = [$values];
28  }
29  return $values;
30  }
31 
38  public function compactValue($value)
39  {
40  if (is_array($value)) {
41  $value = implode(',', $value);
42  }
43  return parent::compactValue($value);
44  }
45 
53  {
54  $values = $this->getEntity()->getData($this->getAttribute()->getAttributeCode());
55  if (!is_array($values)) {
56  $values = explode(',', $values);
57  }
58 
59  switch ($format) {
60  case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON:
61  case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_ARRAY:
62  $output = $values;
63  // fall-through intentional
64  default:
65  $output = [];
66  foreach ($values as $value) {
67  if (!$value) {
68  continue;
69  }
70  $output[] = $this->getAttribute()->getSource()->getOptionText($value);
71  }
72  $output = implode(', ', $output);
73  break;
74  }
75 
76  return $output;
77  }
78 }
_getRequestValue(RequestInterface $request)
extractValue(RequestInterface $request)
Definition: Multiselect.php:23
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16
$format
Definition: list.phtml:12
outputValue($format=\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT)
Definition: Multiselect.php:52