Ejemplo n.º 1
0
 /**
  * Validate post data
  *
  * @param array $data
  * @return bool     Return FALSE if someone item is invalid
  */
 public function validate($data)
 {
     $errorNo = true;
     if (!empty($data['layout_update_xml']) || !empty($data['custom_layout_update_xml'])) {
         /** @var $validatorCustomLayout \Magento\Core\Model\Layout\Update\Validator */
         $validatorCustomLayout = $this->validatorFactory->create();
         if (!empty($data['layout_update_xml']) && !$validatorCustomLayout->isValid($data['layout_update_xml'])) {
             $errorNo = false;
         }
         if (!empty($data['custom_layout_update_xml']) && !$validatorCustomLayout->isValid($data['custom_layout_update_xml'])) {
             $errorNo = false;
         }
         foreach ($validatorCustomLayout->getMessages() as $message) {
             $this->messageManager->addError($message);
         }
     }
     return $errorNo;
 }
Ejemplo n.º 2
0
 /**
  * Validate the custom layout update
  *
  * @param \Magento\Framework\Object $object
  * @return bool
  * @throws Exception
  */
 public function validate($object)
 {
     $attributeName = $this->getAttribute()->getName();
     $xml = trim($object->getData($attributeName));
     if (!$this->getAttribute()->getIsRequired() && empty($xml)) {
         return true;
     }
     /** @var $validator \Magento\Core\Model\Layout\Update\Validator */
     $validator = $this->_layoutUpdateValidatorFactory->create();
     if (!$validator->isValid($xml)) {
         $messages = $validator->getMessages();
         //Add first message to exception
         $massage = array_shift($messages);
         $eavExc = new Exception($massage);
         $eavExc->setAttributeCode($attributeName);
         throw $eavExc;
     }
     return true;
 }