123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Eav\Model\Form;
- /**
- * Eav Form Fieldset Model
- *
- * @api
- * @method int getTypeId()
- * @method \Magento\Eav\Model\Form\Fieldset setTypeId(int $value)
- * @method string getCode()
- * @method \Magento\Eav\Model\Form\Fieldset setCode(string $value)
- * @method int getSortOrder()
- * @method \Magento\Eav\Model\Form\Fieldset setSortOrder(int $value)
- * @since 100.0.2
- */
- class Fieldset extends \Magento\Framework\Model\AbstractModel
- {
- /**
- * Prefix of model events names
- *
- * @var string
- */
- protected $_eventPrefix = 'eav_form_fieldset';
- /**
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $_storeManager;
- /**
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- * @codeCoverageIgnore
- */
- public function __construct(
- \Magento\Framework\Model\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
- \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = []
- ) {
- parent::__construct($context, $registry, $resource, $resourceCollection, $data);
- $this->_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');
- }
- }
|