_storeManager = $storeManager; } /** * Initialize resource model * * @return void * @codeCoverageIgnore */ protected function _construct() { $this->_init(\Magento\Eav\Model\ResourceModel\Form\Fieldset::class); } /** * Validate data before save data * * @throws \Magento\Framework\Exception\LocalizedException * @return $this */ public function beforeSave() { if (!$this->getTypeId()) { throw new \Magento\Framework\Exception\LocalizedException( __('The form type is invalid. Reset the type and try again.') ); } if (!$this->getStoreId() && $this->getLabel()) { $this->setStoreLabel($this->getStoreId(), $this->getLabel()); } return parent::beforeSave(); } /** * Retrieve fieldset labels for stores * * @return array */ public function getLabels() { if (!$this->hasData('labels')) { $this->setData('labels', $this->_getResource()->getLabels($this)); } return $this->_getData('labels'); } /** * Set fieldset store labels * Input array where key - store_id and value = label * * @param array $labels * @return $this * @codeCoverageIgnore */ public function setLabels(array $labels) { return $this->setData('labels', $labels); } /** * Set fieldset store label * * @param int $storeId * @param string $label * @return $this */ public function setStoreLabel($storeId, $label) { $labels = $this->getLabels(); $labels[$storeId] = $label; return $this->setLabels($labels); } /** * Retrieve label store scope * * @return int */ public function getStoreId() { if (!$this->hasStoreId()) { $this->setData('store_id', $this->_storeManager->getStore()->getId()); } return $this->_getData('store_id'); } }