123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Cms\Model;
- use Magento\Cms\Api\Data\PageInterface;
- use Magento\Cms\Helper\Page as PageHelper;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Framework\DataObject\IdentityInterface;
- use Magento\Framework\Exception\LocalizedException;
- use Magento\Framework\Model\AbstractModel;
- /**
- * Cms Page Model
- *
- * @api
- * @method Page setStoreId(array $storeId)
- * @method array getStoreId()
- * @SuppressWarnings(PHPMD.ExcessivePublicCount)
- * @since 100.0.2
- */
- class Page extends AbstractModel implements PageInterface, IdentityInterface
- {
- /**
- * No route page id
- */
- const NOROUTE_PAGE_ID = 'no-route';
- /**#@+
- * Page's Statuses
- */
- const STATUS_ENABLED = 1;
- const STATUS_DISABLED = 0;
- /**#@-*/
- /**
- * CMS page cache tag
- */
- const CACHE_TAG = 'cms_p';
- /**
- * @var string
- */
- protected $_cacheTag = self::CACHE_TAG;
- /**
- * Prefix of model events names
- *
- * @var string
- */
- protected $_eventPrefix = 'cms_page';
- /**
- * @var ScopeConfigInterface
- */
- private $scopeConfig;
- /**
- * Initialize resource model
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init(\Magento\Cms\Model\ResourceModel\Page::class);
- }
- /**
- * Load object data
- *
- * @param int|null $id
- * @param string $field
- * @return $this
- */
- public function load($id, $field = null)
- {
- if ($id === null) {
- return $this->noRoutePage();
- }
- return parent::load($id, $field);
- }
- /**
- * Load No-Route Page
- *
- * @return \Magento\Cms\Model\Page
- */
- public function noRoutePage()
- {
- return $this->load(self::NOROUTE_PAGE_ID, $this->getIdFieldName());
- }
- /**
- * Receive page store ids
- *
- * @return int[]
- */
- public function getStores()
- {
- return $this->hasData('stores') ? $this->getData('stores') : (array)$this->getData('store_id');
- }
- /**
- * Check if page identifier exist for specific store
- * return page id if page exists
- *
- * @param string $identifier
- * @param int $storeId
- * @return int
- */
- public function checkIdentifier($identifier, $storeId)
- {
- return $this->_getResource()->checkIdentifier($identifier, $storeId);
- }
- /**
- * Prepare page's statuses.
- * Available event cms_page_get_available_statuses to customize statuses.
- *
- * @return array
- */
- public function getAvailableStatuses()
- {
- return [self::STATUS_ENABLED => __('Enabled'), self::STATUS_DISABLED => __('Disabled')];
- }
- /**
- * Get identities
- *
- * @return array
- */
- public function getIdentities()
- {
- return [self::CACHE_TAG . '_' . $this->getId()];
- }
- /**
- * Get ID
- *
- * @return int
- */
- public function getId()
- {
- return parent::getData(self::PAGE_ID);
- }
- /**
- * Get identifier
- *
- * @return string
- */
- public function getIdentifier()
- {
- return $this->getData(self::IDENTIFIER);
- }
- /**
- * Get title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->getData(self::TITLE);
- }
- /**
- * Get page layout
- *
- * @return string
- */
- public function getPageLayout()
- {
- return $this->getData(self::PAGE_LAYOUT);
- }
- /**
- * Get meta title
- *
- * @return string|null
- * @since 101.0.0
- */
- public function getMetaTitle()
- {
- return $this->getData(self::META_TITLE);
- }
- /**
- * Get meta keywords
- *
- * @return string
- */
- public function getMetaKeywords()
- {
- return $this->getData(self::META_KEYWORDS);
- }
- /**
- * Get meta description
- *
- * @return string
- */
- public function getMetaDescription()
- {
- return $this->getData(self::META_DESCRIPTION);
- }
- /**
- * Get content heading
- *
- * @return string
- */
- public function getContentHeading()
- {
- return $this->getData(self::CONTENT_HEADING);
- }
- /**
- * Get content
- *
- * @return string
- */
- public function getContent()
- {
- return $this->getData(self::CONTENT);
- }
- /**
- * Get creation time
- *
- * @return string
- */
- public function getCreationTime()
- {
- return $this->getData(self::CREATION_TIME);
- }
- /**
- * Get update time
- *
- * @return string
- */
- public function getUpdateTime()
- {
- return $this->getData(self::UPDATE_TIME);
- }
- /**
- * Get sort order
- *
- * @return string
- */
- public function getSortOrder()
- {
- return $this->getData(self::SORT_ORDER);
- }
- /**
- * Get layout update xml
- *
- * @return string
- */
- public function getLayoutUpdateXml()
- {
- return $this->getData(self::LAYOUT_UPDATE_XML);
- }
- /**
- * Get custom theme
- *
- * @return string
- */
- public function getCustomTheme()
- {
- return $this->getData(self::CUSTOM_THEME);
- }
- /**
- * Get custom root template
- *
- * @return string
- */
- public function getCustomRootTemplate()
- {
- return $this->getData(self::CUSTOM_ROOT_TEMPLATE);
- }
- /**
- * Get custom layout update xml
- *
- * @return string
- */
- public function getCustomLayoutUpdateXml()
- {
- return $this->getData(self::CUSTOM_LAYOUT_UPDATE_XML);
- }
- /**
- * Get custom theme from
- *
- * @return string
- */
- public function getCustomThemeFrom()
- {
- return $this->getData(self::CUSTOM_THEME_FROM);
- }
- /**
- * Get custom theme to
- *
- * @return string
- */
- public function getCustomThemeTo()
- {
- return $this->getData(self::CUSTOM_THEME_TO);
- }
- /**
- * Is active
- *
- * @return bool
- */
- public function isActive()
- {
- return (bool)$this->getData(self::IS_ACTIVE);
- }
- /**
- * Set ID
- *
- * @param int $id
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setId($id)
- {
- return $this->setData(self::PAGE_ID, $id);
- }
- /**
- * Set identifier
- *
- * @param string $identifier
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setIdentifier($identifier)
- {
- return $this->setData(self::IDENTIFIER, $identifier);
- }
- /**
- * Set title
- *
- * @param string $title
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setTitle($title)
- {
- return $this->setData(self::TITLE, $title);
- }
- /**
- * Set page layout
- *
- * @param string $pageLayout
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setPageLayout($pageLayout)
- {
- return $this->setData(self::PAGE_LAYOUT, $pageLayout);
- }
- /**
- * Set meta title
- *
- * @param string $metaTitle
- * @return \Magento\Cms\Api\Data\PageInterface
- * @since 101.0.0
- */
- public function setMetaTitle($metaTitle)
- {
- return $this->setData(self::META_TITLE, $metaTitle);
- }
- /**
- * Set meta keywords
- *
- * @param string $metaKeywords
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setMetaKeywords($metaKeywords)
- {
- return $this->setData(self::META_KEYWORDS, $metaKeywords);
- }
- /**
- * Set meta description
- *
- * @param string $metaDescription
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setMetaDescription($metaDescription)
- {
- return $this->setData(self::META_DESCRIPTION, $metaDescription);
- }
- /**
- * Set content heading
- *
- * @param string $contentHeading
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setContentHeading($contentHeading)
- {
- return $this->setData(self::CONTENT_HEADING, $contentHeading);
- }
- /**
- * Set content
- *
- * @param string $content
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setContent($content)
- {
- return $this->setData(self::CONTENT, $content);
- }
- /**
- * Set creation time
- *
- * @param string $creationTime
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setCreationTime($creationTime)
- {
- return $this->setData(self::CREATION_TIME, $creationTime);
- }
- /**
- * Set update time
- *
- * @param string $updateTime
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setUpdateTime($updateTime)
- {
- return $this->setData(self::UPDATE_TIME, $updateTime);
- }
- /**
- * Set sort order
- *
- * @param string $sortOrder
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setSortOrder($sortOrder)
- {
- return $this->setData(self::SORT_ORDER, $sortOrder);
- }
- /**
- * Set layout update xml
- *
- * @param string $layoutUpdateXml
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setLayoutUpdateXml($layoutUpdateXml)
- {
- return $this->setData(self::LAYOUT_UPDATE_XML, $layoutUpdateXml);
- }
- /**
- * Set custom theme
- *
- * @param string $customTheme
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setCustomTheme($customTheme)
- {
- return $this->setData(self::CUSTOM_THEME, $customTheme);
- }
- /**
- * Set custom root template
- *
- * @param string $customRootTemplate
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setCustomRootTemplate($customRootTemplate)
- {
- return $this->setData(self::CUSTOM_ROOT_TEMPLATE, $customRootTemplate);
- }
- /**
- * Set custom layout update xml
- *
- * @param string $customLayoutUpdateXml
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setCustomLayoutUpdateXml($customLayoutUpdateXml)
- {
- return $this->setData(self::CUSTOM_LAYOUT_UPDATE_XML, $customLayoutUpdateXml);
- }
- /**
- * Set custom theme from
- *
- * @param string $customThemeFrom
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setCustomThemeFrom($customThemeFrom)
- {
- return $this->setData(self::CUSTOM_THEME_FROM, $customThemeFrom);
- }
- /**
- * Set custom theme to
- *
- * @param string $customThemeTo
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setCustomThemeTo($customThemeTo)
- {
- return $this->setData(self::CUSTOM_THEME_TO, $customThemeTo);
- }
- /**
- * Set is active
- *
- * @param int|bool $isActive
- * @return \Magento\Cms\Api\Data\PageInterface
- */
- public function setIsActive($isActive)
- {
- return $this->setData(self::IS_ACTIVE, $isActive);
- }
- /**
- * {@inheritdoc}
- * @since 101.0.0
- */
- public function beforeSave()
- {
- $originalIdentifier = $this->getOrigData('identifier');
- $currentIdentifier = $this->getIdentifier();
- if ($this->hasDataChanges()) {
- $this->setUpdateTime(null);
- }
- if (!$this->getId() || $originalIdentifier === $currentIdentifier) {
- return parent::beforeSave();
- }
- switch ($originalIdentifier) {
- case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_ROUTE_PAGE):
- throw new LocalizedException(
- __('This identifier is reserved for "CMS No Route Page" in configuration.')
- );
- case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_HOME_PAGE):
- throw new LocalizedException(__('This identifier is reserved for "CMS Home Page" in configuration.'));
- case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_COOKIES_PAGE):
- throw new LocalizedException(
- __('This identifier is reserved for "CMS No Cookies Page" in configuration.')
- );
- }
- return parent::beforeSave();
- }
- /**
- * @return ScopeConfigInterface
- */
- private function getScopeConfig()
- {
- if (null === $this->scopeConfig) {
- $this->scopeConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);
- }
- return $this->scopeConfig;
- }
- }
|