Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Group.php
Go to the documentation of this file.
1 <?php
7 
9 
24 {
28  private $translitFilter;
29 
40  public function __construct(
41  \Magento\Framework\Model\Context $context,
42  \Magento\Framework\Registry $registry,
43  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
45  \Magento\Framework\Filter\Translit $translitFilter,
46  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
47  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
48  array $data = []
49  ) {
50  parent::__construct(
51  $context,
52  $registry,
53  $extensionFactory,
55  $resource,
56  $resourceCollection,
57  $data
58  );
59  $this->translitFilter = $translitFilter;
60  }
61 
68  protected function _construct()
69  {
70  $this->_init(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Group::class);
71  }
72 
79  public function itemExists()
80  {
81  return $this->_getResource()->itemExists($this);
82  }
83 
90  public function deleteGroups()
91  {
92  return $this->_getResource()->deleteGroups($this);
93  }
94 
100  public function beforeSave()
101  {
102  if (!$this->getAttributeGroupCode()) {
103  $groupName = $this->getAttributeGroupName();
104  if ($groupName) {
105  $attributeGroupCode = trim(
106  preg_replace(
107  '/[^a-z0-9]+/',
108  '-',
109  $this->translitFilter->filter(strtolower($groupName))
110  ),
111  '-'
112  );
113  if (empty($attributeGroupCode)) {
114  // in the following code md5 is not used for security purposes
115  $attributeGroupCode = md5($groupName);
116  }
117  $this->setAttributeGroupCode($attributeGroupCode);
118  }
119  }
120  return parent::beforeSave();
121  }
122 
127  public function getAttributeGroupId()
128  {
129  return $this->getData(self::GROUP_ID);
130  }
131 
135  public function getAttributeGroupName()
136  {
137  return $this->getData(self::GROUP_NAME);
138  }
139 
143  public function getAttributeSetId()
144  {
145  return $this->getData(self::ATTRIBUTE_SET_ID);
146  }
147 
152  {
153  return $this->setData(self::GROUP_ID, $attributeGroupId);
154  }
155 
159  public function setAttributeGroupName($attributeGroupName)
160  {
161  return $this->setData(self::GROUP_NAME, $attributeGroupName);
162  }
163 
168  {
169  return $this->setData(self::ATTRIBUTE_SET_ID, $attributeSetId);
170  }
171 
177  public function getExtensionAttributes()
178  {
179  return $this->_getExtensionAttributes();
180  }
181 
188  public function setExtensionAttributes(
189  \Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes
190  ) {
191  return $this->_setExtensionAttributes($extensionAttributes);
192  }
193 
194  //@codeCoverageIgnoreEnd
195 }
$attributeGroupId
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Filter\Translit $translitFilter, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Group.php:40
$resource
Definition: bulk.php:12
setExtensionAttributes(\Magento\Eav\Api\Data\AttributeGroupExtensionInterface $extensionAttributes)
Definition: Group.php:188
setAttributeGroupId($attributeGroupId)
Definition: Group.php:151
setAttributeGroupName($attributeGroupName)
Definition: Group.php:159