Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Block.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Cms\Model;
7 
11 
19 {
23  const CACHE_TAG = 'cms_b';
24 
28  const STATUS_ENABLED = 1;
29  const STATUS_DISABLED = 0;
30 
35 
41  protected $_eventPrefix = 'cms_block';
42 
46  protected function _construct()
47  {
48  $this->_init(\Magento\Cms\Model\ResourceModel\Block::class);
49  }
50 
57  public function beforeSave()
58  {
59  if ($this->hasDataChanges()) {
60  $this->setUpdateTime(null);
61  }
62 
63  $needle = 'block_id="' . $this->getId() . '"';
64  if (false == strstr($this->getContent(), $needle)) {
65  return parent::beforeSave();
66  }
67  throw new \Magento\Framework\Exception\LocalizedException(
68  __('Make sure that static block content does not reference the block itself.')
69  );
70  }
71 
77  public function getIdentities()
78  {
79  return [self::CACHE_TAG . '_' . $this->getId(), self::CACHE_TAG . '_' . $this->getIdentifier()];
80  }
81 
87  public function getId()
88  {
89  return $this->getData(self::BLOCK_ID);
90  }
91 
97  public function getIdentifier()
98  {
99  return (string)$this->getData(self::IDENTIFIER);
100  }
101 
107  public function getTitle()
108  {
109  return $this->getData(self::TITLE);
110  }
111 
117  public function getContent()
118  {
119  return $this->getData(self::CONTENT);
120  }
121 
127  public function getCreationTime()
128  {
129  return $this->getData(self::CREATION_TIME);
130  }
131 
137  public function getUpdateTime()
138  {
139  return $this->getData(self::UPDATE_TIME);
140  }
141 
147  public function isActive()
148  {
149  return (bool)$this->getData(self::IS_ACTIVE);
150  }
151 
158  public function setId($id)
159  {
160  return $this->setData(self::BLOCK_ID, $id);
161  }
162 
169  public function setIdentifier($identifier)
170  {
171  return $this->setData(self::IDENTIFIER, $identifier);
172  }
173 
180  public function setTitle($title)
181  {
182  return $this->setData(self::TITLE, $title);
183  }
184 
191  public function setContent($content)
192  {
193  return $this->setData(self::CONTENT, $content);
194  }
195 
202  public function setCreationTime($creationTime)
203  {
204  return $this->setData(self::CREATION_TIME, $creationTime);
205  }
206 
213  public function setUpdateTime($updateTime)
214  {
215  return $this->setData(self::UPDATE_TIME, $updateTime);
216  }
217 
224  public function setIsActive($isActive)
225  {
226  return $this->setData(self::IS_ACTIVE, $isActive);
227  }
228 
234  public function getStores()
235  {
236  return $this->hasData('stores') ? $this->getData('stores') : $this->getData('store_id');
237  }
238 
244  public function getAvailableStatuses()
245  {
246  return [self::STATUS_ENABLED => __('Enabled'), self::STATUS_DISABLED => __('Disabled')];
247  }
248 }
$title
Definition: default.phtml:14
getData($key='', $index=null)
Definition: DataObject.php:119
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
setCreationTime($creationTime)
Definition: Block.php:202
setUpdateTime($updateTime)
Definition: Block.php:213
setContent($content)
Definition: Block.php:191
setIdentifier($identifier)
Definition: Block.php:169
setIsActive($isActive)
Definition: Block.php:224