Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Customlayoutupdate.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\View\Model\Layout\Update\ValidatorFactory;
10 
19 class Customlayoutupdate extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
20 {
27 
33  public function __construct(ValidatorFactory $layoutUpdateValidatorFactory)
34  {
35  $this->_layoutUpdateValidatorFactory = $layoutUpdateValidatorFactory;
36  }
37 
45  public function validate($object)
46  {
47  $attributeName = $this->getAttribute()->getName();
48  $xml = trim($object->getData($attributeName));
49 
50  if (!$this->getAttribute()->getIsRequired() && empty($xml)) {
51  return true;
52  }
53 
55  $validator = $this->_layoutUpdateValidatorFactory->create();
56  if (!$validator->isValid($xml)) {
57  $messages = $validator->getMessages();
58  //Add first message to exception
59  $message = array_shift($messages);
60  $eavExc = new Exception(__($message));
61  $eavExc->setAttributeCode($attributeName);
62  throw $eavExc;
63  }
64  return true;
65  }
66 }
__construct(ValidatorFactory $layoutUpdateValidatorFactory)
__()
Definition: __.php:13
$message