123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Cms\Model;
- use Magento\Cms\Api\Data\BlockInterface;
- use Magento\Framework\DataObject\IdentityInterface;
- use Magento\Framework\Model\AbstractModel;
- /**
- * CMS block model
- *
- * @method Block setStoreId(array $storeId)
- * @method array getStoreId()
- */
- class Block extends AbstractModel implements BlockInterface, IdentityInterface
- {
- /**
- * CMS block cache tag
- */
- const CACHE_TAG = 'cms_b';
- /**#@+
- * Block's statuses
- */
- const STATUS_ENABLED = 1;
- const STATUS_DISABLED = 0;
- /**#@-*/
- /**#@-*/
- protected $_cacheTag = self::CACHE_TAG;
- /**
- * Prefix of model events names
- *
- * @var string
- */
- protected $_eventPrefix = 'cms_block';
- /**
- * @return void
- */
- protected function _construct()
- {
- $this->_init(\Magento\Cms\Model\ResourceModel\Block::class);
- }
- /**
- * Prevent blocks recursion
- *
- * @return AbstractModel
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function beforeSave()
- {
- if ($this->hasDataChanges()) {
- $this->setUpdateTime(null);
- }
- $needle = 'block_id="' . $this->getId() . '"';
- if (false == strstr($this->getContent(), $needle)) {
- return parent::beforeSave();
- }
- throw new \Magento\Framework\Exception\LocalizedException(
- __('Make sure that static block content does not reference the block itself.')
- );
- }
- /**
- * Get identities
- *
- * @return array
- */
- public function getIdentities()
- {
- return [self::CACHE_TAG . '_' . $this->getId(), self::CACHE_TAG . '_' . $this->getIdentifier()];
- }
- /**
- * Retrieve block id
- *
- * @return int
- */
- public function getId()
- {
- return $this->getData(self::BLOCK_ID);
- }
- /**
- * Retrieve block identifier
- *
- * @return string
- */
- public function getIdentifier()
- {
- return (string)$this->getData(self::IDENTIFIER);
- }
- /**
- * Retrieve block title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->getData(self::TITLE);
- }
- /**
- * Retrieve block content
- *
- * @return string
- */
- public function getContent()
- {
- return $this->getData(self::CONTENT);
- }
- /**
- * Retrieve block creation time
- *
- * @return string
- */
- public function getCreationTime()
- {
- return $this->getData(self::CREATION_TIME);
- }
- /**
- * Retrieve block update time
- *
- * @return string
- */
- public function getUpdateTime()
- {
- return $this->getData(self::UPDATE_TIME);
- }
- /**
- * Is active
- *
- * @return bool
- */
- public function isActive()
- {
- return (bool)$this->getData(self::IS_ACTIVE);
- }
- /**
- * Set ID
- *
- * @param int $id
- * @return BlockInterface
- */
- public function setId($id)
- {
- return $this->setData(self::BLOCK_ID, $id);
- }
- /**
- * Set identifier
- *
- * @param string $identifier
- * @return BlockInterface
- */
- public function setIdentifier($identifier)
- {
- return $this->setData(self::IDENTIFIER, $identifier);
- }
- /**
- * Set title
- *
- * @param string $title
- * @return BlockInterface
- */
- public function setTitle($title)
- {
- return $this->setData(self::TITLE, $title);
- }
- /**
- * Set content
- *
- * @param string $content
- * @return BlockInterface
- */
- public function setContent($content)
- {
- return $this->setData(self::CONTENT, $content);
- }
- /**
- * Set creation time
- *
- * @param string $creationTime
- * @return BlockInterface
- */
- public function setCreationTime($creationTime)
- {
- return $this->setData(self::CREATION_TIME, $creationTime);
- }
- /**
- * Set update time
- *
- * @param string $updateTime
- * @return BlockInterface
- */
- public function setUpdateTime($updateTime)
- {
- return $this->setData(self::UPDATE_TIME, $updateTime);
- }
- /**
- * Set is active
- *
- * @param bool|int $isActive
- * @return BlockInterface
- */
- public function setIsActive($isActive)
- {
- return $this->setData(self::IS_ACTIVE, $isActive);
- }
- /**
- * Receive page store ids
- *
- * @return int[]
- */
- public function getStores()
- {
- return $this->hasData('stores') ? $this->getData('stores') : $this->getData('store_id');
- }
- /**
- * Prepare block's statuses.
- *
- * @return array
- */
- public function getAvailableStatuses()
- {
- return [self::STATUS_ENABLED => __('Enabled'), self::STATUS_DISABLED => __('Disabled')];
- }
- }
|