_eavConfig = $eavConfig; } /** * Initialize resource model * * @return void * @codeCoverageIgnore */ protected function _construct() { $this->_init(\Magento\Eav\Model\ResourceModel\Form\Element::class); } /** * Validate data before save data * * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeSave() { if (!$this->getTypeId()) { throw new LocalizedException(__('The form type is invalid. Reset the type and try again.')); } if (!$this->getAttributeId()) { throw new LocalizedException(__('The EAV attribute is invalid. Verify the attribute and try again.')); } return parent::beforeSave(); } /** * Retrieve EAV Attribute instance * * @return \Magento\Eav\Model\Entity\Attribute */ public function getAttribute() { if (!$this->hasData('attribute')) { $attribute = $this->_eavConfig->getAttribute($this->getEntityTypeId(), $this->getAttributeId()); $this->setData('attribute', $attribute); } return $this->_getData('attribute'); } }