Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArrayBackend.php
Go to the documentation of this file.
1 <?php
7 
14 class ArrayBackend extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
15 {
22  public function beforeSave($object)
23  {
24  $attributeCode = $this->getAttribute()->getAttributeCode();
25  $data = $object->getData($attributeCode);
26  if (is_array($data)) {
27  $data = array_filter($data, function ($value) {
28  return $value === '0' || !empty($value);
29  });
30  $object->setData($attributeCode, implode(',', $data));
31  }
32 
33  return parent::beforeSave($object);
34  }
35 
42  public function validate($object)
43  {
44  $attributeCode = $this->getAttribute()->getAttributeCode();
45  $data = $object->getData($attributeCode);
46  if (is_array($data)) {
47  $object->setData($attributeCode, implode(',', array_filter($data)));
48  } elseif (empty($data)) {
49  $object->setData($attributeCode, null);
50  }
51  return parent::validate($object);
52  }
53 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16
$attributeCode
Definition: extend.phtml:12