Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Page.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Cms\Model;
7 
9 use Magento\Cms\Helper\Page as PageHelper;
14 
25 {
29  const NOROUTE_PAGE_ID = 'no-route';
30 
34  const STATUS_ENABLED = 1;
35  const STATUS_DISABLED = 0;
41  const CACHE_TAG = 'cms_p';
42 
47 
53  protected $_eventPrefix = 'cms_page';
54 
58  private $scopeConfig;
59 
65  protected function _construct()
66  {
67  $this->_init(\Magento\Cms\Model\ResourceModel\Page::class);
68  }
69 
77  public function load($id, $field = null)
78  {
79  if ($id === null) {
80  return $this->noRoutePage();
81  }
82  return parent::load($id, $field);
83  }
84 
90  public function noRoutePage()
91  {
92  return $this->load(self::NOROUTE_PAGE_ID, $this->getIdFieldName());
93  }
94 
100  public function getStores()
101  {
102  return $this->hasData('stores') ? $this->getData('stores') : (array)$this->getData('store_id');
103  }
104 
113  public function checkIdentifier($identifier, $storeId)
114  {
115  return $this->_getResource()->checkIdentifier($identifier, $storeId);
116  }
117 
124  public function getAvailableStatuses()
125  {
126  return [self::STATUS_ENABLED => __('Enabled'), self::STATUS_DISABLED => __('Disabled')];
127  }
128 
134  public function getIdentities()
135  {
136  return [self::CACHE_TAG . '_' . $this->getId()];
137  }
138 
144  public function getId()
145  {
146  return parent::getData(self::PAGE_ID);
147  }
148 
154  public function getIdentifier()
155  {
156  return $this->getData(self::IDENTIFIER);
157  }
158 
164  public function getTitle()
165  {
166  return $this->getData(self::TITLE);
167  }
168 
174  public function getPageLayout()
175  {
176  return $this->getData(self::PAGE_LAYOUT);
177  }
178 
185  public function getMetaTitle()
186  {
187  return $this->getData(self::META_TITLE);
188  }
189 
195  public function getMetaKeywords()
196  {
197  return $this->getData(self::META_KEYWORDS);
198  }
199 
205  public function getMetaDescription()
206  {
207  return $this->getData(self::META_DESCRIPTION);
208  }
209 
215  public function getContentHeading()
216  {
217  return $this->getData(self::CONTENT_HEADING);
218  }
219 
225  public function getContent()
226  {
227  return $this->getData(self::CONTENT);
228  }
229 
235  public function getCreationTime()
236  {
237  return $this->getData(self::CREATION_TIME);
238  }
239 
245  public function getUpdateTime()
246  {
247  return $this->getData(self::UPDATE_TIME);
248  }
249 
255  public function getSortOrder()
256  {
257  return $this->getData(self::SORT_ORDER);
258  }
259 
265  public function getLayoutUpdateXml()
266  {
267  return $this->getData(self::LAYOUT_UPDATE_XML);
268  }
269 
275  public function getCustomTheme()
276  {
277  return $this->getData(self::CUSTOM_THEME);
278  }
279 
285  public function getCustomRootTemplate()
286  {
287  return $this->getData(self::CUSTOM_ROOT_TEMPLATE);
288  }
289 
295  public function getCustomLayoutUpdateXml()
296  {
297  return $this->getData(self::CUSTOM_LAYOUT_UPDATE_XML);
298  }
299 
305  public function getCustomThemeFrom()
306  {
307  return $this->getData(self::CUSTOM_THEME_FROM);
308  }
309 
315  public function getCustomThemeTo()
316  {
317  return $this->getData(self::CUSTOM_THEME_TO);
318  }
319 
325  public function isActive()
326  {
327  return (bool)$this->getData(self::IS_ACTIVE);
328  }
329 
336  public function setId($id)
337  {
338  return $this->setData(self::PAGE_ID, $id);
339  }
340 
347  public function setIdentifier($identifier)
348  {
349  return $this->setData(self::IDENTIFIER, $identifier);
350  }
351 
358  public function setTitle($title)
359  {
360  return $this->setData(self::TITLE, $title);
361  }
362 
369  public function setPageLayout($pageLayout)
370  {
371  return $this->setData(self::PAGE_LAYOUT, $pageLayout);
372  }
373 
381  public function setMetaTitle($metaTitle)
382  {
383  return $this->setData(self::META_TITLE, $metaTitle);
384  }
385 
392  public function setMetaKeywords($metaKeywords)
393  {
394  return $this->setData(self::META_KEYWORDS, $metaKeywords);
395  }
396 
403  public function setMetaDescription($metaDescription)
404  {
405  return $this->setData(self::META_DESCRIPTION, $metaDescription);
406  }
407 
414  public function setContentHeading($contentHeading)
415  {
416  return $this->setData(self::CONTENT_HEADING, $contentHeading);
417  }
418 
425  public function setContent($content)
426  {
427  return $this->setData(self::CONTENT, $content);
428  }
429 
436  public function setCreationTime($creationTime)
437  {
438  return $this->setData(self::CREATION_TIME, $creationTime);
439  }
440 
447  public function setUpdateTime($updateTime)
448  {
449  return $this->setData(self::UPDATE_TIME, $updateTime);
450  }
451 
458  public function setSortOrder($sortOrder)
459  {
460  return $this->setData(self::SORT_ORDER, $sortOrder);
461  }
462 
469  public function setLayoutUpdateXml($layoutUpdateXml)
470  {
471  return $this->setData(self::LAYOUT_UPDATE_XML, $layoutUpdateXml);
472  }
473 
480  public function setCustomTheme($customTheme)
481  {
482  return $this->setData(self::CUSTOM_THEME, $customTheme);
483  }
484 
491  public function setCustomRootTemplate($customRootTemplate)
492  {
493  return $this->setData(self::CUSTOM_ROOT_TEMPLATE, $customRootTemplate);
494  }
495 
502  public function setCustomLayoutUpdateXml($customLayoutUpdateXml)
503  {
504  return $this->setData(self::CUSTOM_LAYOUT_UPDATE_XML, $customLayoutUpdateXml);
505  }
506 
513  public function setCustomThemeFrom($customThemeFrom)
514  {
515  return $this->setData(self::CUSTOM_THEME_FROM, $customThemeFrom);
516  }
517 
524  public function setCustomThemeTo($customThemeTo)
525  {
526  return $this->setData(self::CUSTOM_THEME_TO, $customThemeTo);
527  }
528 
535  public function setIsActive($isActive)
536  {
537  return $this->setData(self::IS_ACTIVE, $isActive);
538  }
539 
544  public function beforeSave()
545  {
546  $originalIdentifier = $this->getOrigData('identifier');
547  $currentIdentifier = $this->getIdentifier();
548 
549  if ($this->hasDataChanges()) {
550  $this->setUpdateTime(null);
551  }
552 
553  if (!$this->getId() || $originalIdentifier === $currentIdentifier) {
554  return parent::beforeSave();
555  }
556 
557  switch ($originalIdentifier) {
558  case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_ROUTE_PAGE):
559  throw new LocalizedException(
560  __('This identifier is reserved for "CMS No Route Page" in configuration.')
561  );
562  case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_HOME_PAGE):
563  throw new LocalizedException(__('This identifier is reserved for "CMS Home Page" in configuration.'));
564  case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_COOKIES_PAGE):
565  throw new LocalizedException(
566  __('This identifier is reserved for "CMS No Cookies Page" in configuration.')
567  );
568  }
569 
570  return parent::beforeSave();
571  }
572 
576  private function getScopeConfig()
577  {
578  if (null === $this->scopeConfig) {
579  $this->scopeConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);
580  }
581 
582  return $this->scopeConfig;
583  }
584 }
$title
Definition: default.phtml:14
setCustomTheme($customTheme)
Definition: Page.php:480
getData($key='', $index=null)
Definition: DataObject.php:119
setCustomThemeFrom($customThemeFrom)
Definition: Page.php:513
setLayoutUpdateXml($layoutUpdateXml)
Definition: Page.php:469
$id
Definition: fieldset.phtml:14
setMetaTitle($metaTitle)
Definition: Page.php:381
const NOROUTE_PAGE_ID
Definition: Page.php:29
setContentHeading($contentHeading)
Definition: Page.php:414
__()
Definition: __.php:13
setCustomLayoutUpdateXml($customLayoutUpdateXml)
Definition: Page.php:502
setIsActive($isActive)
Definition: Page.php:535
const STATUS_ENABLED
Definition: Page.php:34
setUpdateTime($updateTime)
Definition: Page.php:447
setSortOrder($sortOrder)
Definition: Page.php:458
checkIdentifier($identifier, $storeId)
Definition: Page.php:113
setCustomRootTemplate($customRootTemplate)
Definition: Page.php:491
load($id, $field=null)
Definition: Page.php:77
setContent($content)
Definition: Page.php:425
setIdentifier($identifier)
Definition: Page.php:347
const STATUS_DISABLED
Definition: Page.php:35
setPageLayout($pageLayout)
Definition: Page.php:369
setMetaKeywords($metaKeywords)
Definition: Page.php:392
setMetaDescription($metaDescription)
Definition: Page.php:403
setCreationTime($creationTime)
Definition: Page.php:436
setCustomThemeTo($customThemeTo)
Definition: Page.php:524