Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Backend.php
Go to the documentation of this file.
1 <?php
7 
13 class Backend extends \Magento\Framework\Validator\AbstractValidator
14 {
22  public function isValid($entity)
23  {
24  $this->_messages = [];
25  if (!$entity instanceof \Magento\Framework\Model\AbstractModel) {
26  throw new \InvalidArgumentException('Model must be extended from \Magento\Framework\Model\AbstractModel');
27  }
29  $resource = $entity->getResource();
30  if (!$resource instanceof \Magento\Eav\Model\Entity\AbstractEntity) {
31  throw new \InvalidArgumentException(
32  'Model resource must be extended from \Magento\Eav\Model\Entity\AbstractEntity'
33  );
34  }
35  $resource->loadAllAttributes($entity);
36  $attributes = $resource->getAttributesByCode();
38  foreach ($attributes as $attribute) {
39  $backend = $attribute->getBackend();
40  if (!method_exists($backend, 'validate') || !is_callable([$backend, 'validate'])) {
41  continue;
42  }
43  try {
44  $result = $backend->validate($entity);
45  if (false === $result) {
46  $this->_messages[$attribute->getAttributeCode()][] = __(
47  'The value of attribute "%1" is invalid.',
48  $attribute->getAttributeCode()
49  );
50  } elseif (is_string($result)) {
51  $this->_messages[$attribute->getAttributeCode()][] = $result;
52  }
53  } catch (\Magento\Framework\Exception\LocalizedException $e) {
54  $this->_messages[$attribute->getAttributeCode()][] = $e->getMessage();
55  }
56  }
57  return 0 == count($this->_messages);
58  }
59 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$entity
Definition: element.phtml:22
$attributes
Definition: matrix.phtml:13