Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
Element.php
Go to the documentation of this file.
1 <?php
8 
10 
26 {
32  protected $_eventPrefix = 'eav_form_element';
33 
37  protected $_eavConfig;
38 
48  public function __construct(
49  \Magento\Framework\Model\Context $context,
50  \Magento\Framework\Registry $registry,
51  \Magento\Eav\Model\Config $eavConfig,
52  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
53  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
54  array $data = []
55  ) {
56  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
57  $this->_eavConfig = $eavConfig;
58  }
59 
66  protected function _construct()
67  {
68  $this->_init(\Magento\Eav\Model\ResourceModel\Form\Element::class);
69  }
70 
77  public function beforeSave()
78  {
79  if (!$this->getTypeId()) {
80  throw new LocalizedException(__('The form type is invalid. Reset the type and try again.'));
81  }
82  if (!$this->getAttributeId()) {
83  throw new LocalizedException(__('The EAV attribute is invalid. Verify the attribute and try again.'));
84  }
85 
86  return parent::beforeSave();
87  }
88 
94  public function getAttribute()
95  {
96  if (!$this->hasData('attribute')) {
97  $attribute = $this->_eavConfig->getAttribute($this->getEntityTypeId(), $this->getAttributeId());
98  $this->setData('attribute', $attribute);
99  }
100  return $this->_getData('attribute');
101  }
102 }
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Element.php:48
__()
Definition: __.php:13
$resource
Definition: bulk.php:12