Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Fieldset.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Eav\Model\Form;
8 
22 {
28  protected $_eventPrefix = 'eav_form_fieldset';
29 
33  protected $_storeManager;
34 
44  public function __construct(
45  \Magento\Framework\Model\Context $context,
46  \Magento\Framework\Registry $registry,
47  \Magento\Store\Model\StoreManagerInterface $storeManager,
48  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
49  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
50  array $data = []
51  ) {
52  parent::__construct($context, $registry, $resource, $resourceCollection, $data);
53  $this->_storeManager = $storeManager;
54  }
55 
62  protected function _construct()
63  {
64  $this->_init(\Magento\Eav\Model\ResourceModel\Form\Fieldset::class);
65  }
66 
73  public function beforeSave()
74  {
75  if (!$this->getTypeId()) {
76  throw new \Magento\Framework\Exception\LocalizedException(
77  __('The form type is invalid. Reset the type and try again.')
78  );
79  }
80  if (!$this->getStoreId() && $this->getLabel()) {
81  $this->setStoreLabel($this->getStoreId(), $this->getLabel());
82  }
83 
84  return parent::beforeSave();
85  }
86 
92  public function getLabels()
93  {
94  if (!$this->hasData('labels')) {
95  $this->setData('labels', $this->_getResource()->getLabels($this));
96  }
97  return $this->_getData('labels');
98  }
99 
108  public function setLabels(array $labels)
109  {
110  return $this->setData('labels', $labels);
111  }
112 
120  public function setStoreLabel($storeId, $label)
121  {
122  $labels = $this->getLabels();
123  $labels[$storeId] = $label;
124 
125  return $this->setLabels($labels);
126  }
127 
133  public function getStoreId()
134  {
135  if (!$this->hasStoreId()) {
136  $this->setData('store_id', $this->_storeManager->getStore()->getId());
137  }
138  return $this->_getData('store_id');
139  }
140 }
__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=[])
Definition: Fieldset.php:44
$storeManager
__()
Definition: __.php:13
$resource
Definition: bulk.php:12
$label
Definition: details.phtml:21
setStoreLabel($storeId, $label)
Definition: Fieldset.php:120