Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Block Class Reference
Inheritance diagram for Block:
AbstractModel BlockInterface IdentityInterface DataObject

Public Member Functions

 beforeSave ()
 
 getIdentities ()
 
 getId ()
 
 getIdentifier ()
 
 getTitle ()
 
 getContent ()
 
 getCreationTime ()
 
 getUpdateTime ()
 
 isActive ()
 
 setId ($id)
 
 setIdentifier ($identifier)
 
 setTitle ($title)
 
 setContent ($content)
 
 setCreationTime ($creationTime)
 
 setUpdateTime ($updateTime)
 
 setIsActive ($isActive)
 
 getStores ()
 
 getAvailableStatuses ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const CACHE_TAG = 'cms_b'
 
const STATUS_ENABLED = 1
 
const STATUS_DISABLED = 0
 
- Data Fields inherited from BlockInterface
const BLOCK_ID = 'block_id'
 
const IDENTIFIER = 'identifier'
 
const TITLE = 'title'
 
const CONTENT = 'content'
 
const CREATION_TIME = 'creation_time'
 
const UPDATE_TIME = 'update_time'
 
const IS_ACTIVE = 'is_active'
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_cacheTag = self::CACHE_TAG
 
 $_eventPrefix = 'cms_block'
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

CMS block model

@method Block setStoreId(array $storeId) @method array getStoreId()

Definition at line 18 of file Block.php.

Member Function Documentation

◆ _construct()

_construct ( )
protected
Returns
void

Definition at line 46 of file Block.php.

◆ beforeSave()

beforeSave ( )

Prevent blocks recursion

Returns
AbstractModel
Exceptions

Definition at line 57 of file Block.php.

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  }
__()
Definition: __.php:13
setUpdateTime($updateTime)
Definition: Block.php:213

◆ getAvailableStatuses()

getAvailableStatuses ( )

Prepare block's statuses.

Returns
array

Definition at line 244 of file Block.php.

245  {
246  return [self::STATUS_ENABLED => __('Enabled'), self::STATUS_DISABLED => __('Disabled')];
247  }
__()
Definition: __.php:13

◆ getContent()

getContent ( )

Retrieve block content

Returns
string

Implements BlockInterface.

Definition at line 117 of file Block.php.

118  {
119  return $this->getData(self::CONTENT);
120  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getCreationTime()

getCreationTime ( )

Retrieve block creation time

Returns
string

Implements BlockInterface.

Definition at line 127 of file Block.php.

128  {
129  return $this->getData(self::CREATION_TIME);
130  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getId()

getId ( )

Retrieve block id

Returns
int

Implements BlockInterface.

Definition at line 87 of file Block.php.

88  {
89  return $this->getData(self::BLOCK_ID);
90  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getIdentifier()

getIdentifier ( )

Retrieve block identifier

Returns
string

Implements BlockInterface.

Definition at line 97 of file Block.php.

98  {
99  return (string)$this->getData(self::IDENTIFIER);
100  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getIdentities()

getIdentities ( )

Get identities

Returns
array

Implements IdentityInterface.

Definition at line 77 of file Block.php.

78  {
79  return [self::CACHE_TAG . '_' . $this->getId(), self::CACHE_TAG . '_' . $this->getIdentifier()];
80  }

◆ getStores()

getStores ( )

Receive page store ids

Returns
int[]

Definition at line 234 of file Block.php.

235  {
236  return $this->hasData('stores') ? $this->getData('stores') : $this->getData('store_id');
237  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getTitle()

getTitle ( )

Retrieve block title

Returns
string

Implements BlockInterface.

Definition at line 107 of file Block.php.

108  {
109  return $this->getData(self::TITLE);
110  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getUpdateTime()

getUpdateTime ( )

Retrieve block update time

Returns
string

Implements BlockInterface.

Definition at line 137 of file Block.php.

138  {
139  return $this->getData(self::UPDATE_TIME);
140  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ isActive()

isActive ( )

Is active

Returns
bool

Implements BlockInterface.

Definition at line 147 of file Block.php.

148  {
149  return (bool)$this->getData(self::IS_ACTIVE);
150  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ setContent()

setContent (   $content)

Set content

Parameters
string$content
Returns
BlockInterface

Implements BlockInterface.

Definition at line 191 of file Block.php.

192  {
193  return $this->setData(self::CONTENT, $content);
194  }

◆ setCreationTime()

setCreationTime (   $creationTime)

Set creation time

Parameters
string$creationTime
Returns
BlockInterface

Implements BlockInterface.

Definition at line 202 of file Block.php.

203  {
204  return $this->setData(self::CREATION_TIME, $creationTime);
205  }

◆ setId()

setId (   $id)

Set ID

Parameters
int$id
Returns
BlockInterface

Implements BlockInterface.

Definition at line 158 of file Block.php.

159  {
160  return $this->setData(self::BLOCK_ID, $id);
161  }
$id
Definition: fieldset.phtml:14

◆ setIdentifier()

setIdentifier (   $identifier)

Set identifier

Parameters
string$identifier
Returns
BlockInterface

Implements BlockInterface.

Definition at line 169 of file Block.php.

170  {
171  return $this->setData(self::IDENTIFIER, $identifier);
172  }

◆ setIsActive()

setIsActive (   $isActive)

Set is active

Parameters
bool | int$isActive
Returns
BlockInterface

Implements BlockInterface.

Definition at line 224 of file Block.php.

225  {
226  return $this->setData(self::IS_ACTIVE, $isActive);
227  }

◆ setTitle()

setTitle (   $title)

Set title

Parameters
string$title
Returns
BlockInterface

Implements BlockInterface.

Definition at line 180 of file Block.php.

181  {
182  return $this->setData(self::TITLE, $title);
183  }
$title
Definition: default.phtml:14

◆ setUpdateTime()

setUpdateTime (   $updateTime)

Set update time

Parameters
string$updateTime
Returns
BlockInterface

Implements BlockInterface.

Definition at line 213 of file Block.php.

214  {
215  return $this->setData(self::UPDATE_TIME, $updateTime);
216  }

Field Documentation

◆ $_cacheTag

$_cacheTag = self::CACHE_TAG
protected

#- #-

Definition at line 34 of file Block.php.

◆ $_eventPrefix

$_eventPrefix = 'cms_block'
protected

Definition at line 41 of file Block.php.

◆ CACHE_TAG

const CACHE_TAG = 'cms_b'

CMS block cache tag

Definition at line 23 of file Block.php.

◆ STATUS_DISABLED

const STATUS_DISABLED = 0

Definition at line 29 of file Block.php.

◆ STATUS_ENABLED

const STATUS_ENABLED = 1

#+ Block's statuses

Definition at line 28 of file Block.php.


The documentation for this class was generated from the following file: