Same name in this branch
- 10 core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
- 10 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent
- 10 core/modules/block_content/src/Plugin/views/wizard/BlockContent.php \Drupal\block_content\Plugin\views\wizard\BlockContent
Same name and namespace in other branches
- 8.9.x core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
- 9 core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
Defines the content block entity class.
@ContentEntityType( id = "block_content", label = @Translation("Content block"), label_collection = @Translation("Content blocks"), label_singular = @Translation("content block"), label_plural = @Translation("content blocks"), label_count = @PluralTranslation( singular = "@count content block", plural = "@count content blocks", ), bundle_label = @Translation("Block type"), handlers = { "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage", "storage_schema" = "Drupal\block_content\BlockContentStorageSchema", "access" = "Drupal\block_content\BlockContentAccessControlHandler", "list_builder" = "Drupal\block_content\BlockContentListBuilder", "view_builder" = "Drupal\block_content\BlockContentViewBuilder", "views_data" = "Drupal\block_content\BlockContentViewsData", "form" = { "add" = "Drupal\block_content\BlockContentForm", "edit" = "Drupal\block_content\BlockContentForm", "delete" = "Drupal\block_content\Form\BlockContentDeleteForm", "default" = "Drupal\block_content\BlockContentForm", "revision-delete" = \Drupal\Core\Entity\Form\RevisionDeleteForm::class, "revision-revert" = \Drupal\Core\Entity\Form\RevisionRevertForm::class, }, "route_provider" = { "revision" = \Drupal\Core\Entity\Routing\RevisionHtmlRouteProvider::class, }, "translation" = "Drupal\block_content\BlockContentTranslationHandler" }, admin_permission = "administer block content", collection_permission = "access block library", base_table = "block_content", revision_table = "block_content_revision", data_table = "block_content_field_data", revision_data_table = "block_content_field_revision", show_revision_ui = TRUE, links = { "canonical" = "/admin/content/block/{block_content}", "delete-form" = "/admin/content/block/{block_content}/delete", "edit-form" = "/admin/content/block/{block_content}", "collection" = "/admin/content/block", "create" = "/block", "revision-delete-form" = "/admin/content/block/{block_content}/revision/{block_content_revision}/delete", "revision-revert-form" = "/admin/content/block/{block_content}/revision/{block_content_revision}/revert", "version-history" = "/admin/content/block/{block_content}/revisions", }, translatable = TRUE, entity_keys = { "id" = "id", "revision" = "revision_id", "bundle" = "type", "label" = "info", "langcode" = "langcode", "uuid" = "uuid", "published" = "status", }, revision_metadata_keys = { "revision_user" = "revision_user", "revision_created" = "revision_created", "revision_log_message" = "revision_log" }, bundle_entity_type = "block_content_type", field_ui_base_route = "entity.block_content_type.edit_form", render_cache = FALSE, )
Note that render caching of block_content entities is disabled because they are always rendered as blocks, and blocks already have their own render caching. See https://www.drupal.org/node/2284917#comment-9132521 for more information.
Hierarchy
- class \Drupal\Core\Entity\EditorialContentEntityBase extends \Drupal\Core\Entity\ContentEntityBase implements EntityChangedInterface, EntityPublishedInterface, RevisionLogInterface uses EntityChangedTrait, EntityPublishedTrait, RevisionLogEntityTrait
- class \Drupal\block_content\Entity\BlockContent implements BlockContentInterface uses RefinableDependentAccessTrait
Expanded class hierarchy of BlockContent
32 files declare their use of BlockContent
- BlockContentCacheTagsTest.php in core/
modules/ block_content/ tests/ src/ Functional/ BlockContentCacheTagsTest.php - BlockContentCreationTest.php in core/
modules/ block_content/ tests/ src/ Functional/ BlockContentCreationTest.php - BlockContentDeletionTest.php in core/
modules/ block_content/ tests/ src/ Kernel/ BlockContentDeletionTest.php - BlockContentDeriverTest.php in core/
modules/ block_content/ tests/ src/ Kernel/ BlockContentDeriverTest.php - BlockContentEntityReferenceSelectionTest.php in core/
modules/ block_content/ tests/ src/ Kernel/ BlockContentEntityReferenceSelectionTest.php
File
- core/
modules/ block_content/ src/ Entity/ BlockContent.php, line 88
Namespace
Drupal\block_content\EntityView source
class BlockContent extends EditorialContentEntityBase implements BlockContentInterface {
use RefinableDependentAccessTrait;
/**
* The theme the block is being created in.
*
* When creating a new content block from the block library, the user is
* redirected to the configure form for that block in the given theme. The
* theme is stored against the block when the content block add form is shown.
*
* @var string
*/
protected $theme;
/**
* {@inheritdoc}
*/
public function createDuplicate() {
$duplicate = parent::createDuplicate();
$duplicate->revision_id->value = NULL;
$duplicate->id->value = NULL;
return $duplicate;
}
/**
* {@inheritdoc}
*/
public function setTheme($theme) {
$this->theme = $theme;
return $this;
}
/**
* {@inheritdoc}
*/
public function getTheme() {
return $this->theme;
}
/**
* {@inheritdoc}
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
if ($this
->isReusable() || isset($this->original) && $this->original
->isReusable()) {
static::invalidateBlockPluginCache();
}
}
/**
* {@inheritdoc}
*/
public static function preDelete(EntityStorageInterface $storage, array $entities) {
parent::preDelete($storage, $entities);
/** @var \Drupal\block_content\BlockContentInterface $block */
foreach ($entities as $block) {
foreach ($block
->getInstances() as $instance) {
$instance
->delete();
}
}
}
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
/** @var \Drupal\block_content\BlockContentInterface $block */
foreach ($entities as $block) {
if ($block
->isReusable()) {
// If any deleted blocks are reusable clear the block cache.
static::invalidateBlockPluginCache();
return;
}
}
}
/**
* {@inheritdoc}
*/
public function getInstances() {
return \Drupal::entityTypeManager()
->getStorage('block')
->loadByProperties([
'plugin' => 'block_content:' . $this
->uuid(),
]);
}
/**
* {@inheritdoc}
*/
public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
parent::preSaveRevision($storage, $record);
if (!$this
->isNewRevision() && isset($this->original) && empty($record->revision_log_message)) {
// If we are updating an existing block_content without adding a new
// revision and the user did not supply a revision log, keep the existing
// one.
$record->revision_log = $this->original
->getRevisionLogMessage();
}
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
$fields = parent::baseFieldDefinitions($entity_type);
$fields['id']
->setLabel(t('Content block ID'))
->setDescription(t('The content block ID.'));
$fields['uuid']
->setDescription(t('The content block UUID.'));
$fields['revision_id']
->setDescription(t('The revision ID.'));
$fields['langcode']
->setDescription(t('The content block language code.'));
$fields['type']
->setLabel(t('Block type'))
->setDescription(t('The block type.'));
$fields['revision_log']
->setDescription(t('The log entry explaining the changes in this revision.'));
$fields['info'] = BaseFieldDefinition::create('string')
->setLabel(t('Block description'))
->setDescription(t('A brief description of your block.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setRequired(TRUE)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
])
->setDisplayConfigurable('form', TRUE);
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the content block was last edited.'))
->setTranslatable(TRUE)
->setRevisionable(TRUE);
$fields['reusable'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Reusable'))
->setDescription(t('A boolean indicating whether this block is reusable.'))
->setTranslatable(FALSE)
->setRevisionable(FALSE)
->setDefaultValue(TRUE);
return $fields;
}
/**
* {@inheritdoc}
*/
public function setInfo($info) {
$this
->set('info', $info);
return $this;
}
/**
* {@inheritdoc}
*/
public function isReusable() {
return (bool) $this
->get('reusable')->value;
}
/**
* {@inheritdoc}
*/
public function setReusable() {
return $this
->set('reusable', TRUE);
}
/**
* {@inheritdoc}
*/
public function setNonReusable() {
return $this
->set('reusable', FALSE);
}
/**
* Invalidates the block plugin cache after changes and deletions.
*/
protected static function invalidateBlockPluginCache() {
// Invalidate the block cache to update content block-based derivatives.
\Drupal::service('plugin.manager.block')
->clearCachedDefinitions();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AccessibleInterface:: |
public | function | Checks data value access. | 6 |
BlockContent:: |
protected | property | The theme the block is being created in. | |
BlockContent:: |
public static | function |
Provides base field definitions for an entity type. Overrides EditorialContentEntityBase:: |
|
BlockContent:: |
public | function |
Creates a duplicate of the entity. Overrides EntityInterface:: |
|
BlockContent:: |
public | function |
Gets the configured instances of this content block. Overrides BlockContentInterface:: |
|
BlockContent:: |
public | function |
Gets the theme value. Overrides BlockContentInterface:: |
|
BlockContent:: |
protected static | function | Invalidates the block plugin cache after changes and deletions. | |
BlockContent:: |
public | function |
Determines if the block is reusable or not. Overrides BlockContentInterface:: |
|
BlockContent:: |
public static | function |
Acts on deleted entities before the delete hook is invoked. Overrides EntityInterface:: |
|
BlockContent:: |
public | function |
Acts on a saved entity before the insert or update hook is invoked. Overrides EntityInterface:: |
|
BlockContent:: |
public static | function |
Acts on entities before they are deleted and before hooks are invoked. Overrides EntityInterface:: |
|
BlockContent:: |
public | function |
Acts on a revision before it gets saved. Overrides RevisionableInterface:: |
|
BlockContent:: |
public | function |
Sets the block description. Overrides BlockContentInterface:: |
|
BlockContent:: |
public | function |
Sets the block to be non-reusable. Overrides BlockContentInterface:: |
|
BlockContent:: |
public | function |
Sets the block to be reusable. Overrides BlockContentInterface:: |
|
BlockContent:: |
public | function |
Sets the theme value. Overrides BlockContentInterface:: |
|
CacheableDependencyInterface:: |
public | function | The cache contexts associated with this object. | 19 |
CacheableDependencyInterface:: |
public | function | The maximum age for which this object may be cached. | 19 |
CacheableDependencyInterface:: |
public | function | The cache tags associated with this object. | 12 |
EntityChangedTrait:: |
public | function | Gets the timestamp of the last entity change for the current translation. | |
EntityChangedTrait:: |
public | function | Returns the timestamp of the last entity change across all translations. | |
EntityChangedTrait:: |
public | function | Sets the timestamp of the last entity change for the current translation. | |
EntityInterface:: |
public | function | Gets the bundle of the entity. | 1 |
EntityInterface:: |
public static | function | Constructs a new entity object, without permanently saving it. | 1 |
EntityInterface:: |
public | function | Deletes an entity permanently. | 1 |
EntityInterface:: |
public | function | Enforces an entity to be new. | 1 |
EntityInterface:: |
public | function | Returns the cache tags that should be used to invalidate caches. | 3 |
EntityInterface:: |
public | function | Gets the key that is used to store configuration dependencies. | 1 |
EntityInterface:: |
public | function | Gets the configuration dependency name. | 1 |
EntityInterface:: |
public | function | Gets the configuration target identifier for the entity. | 1 |
EntityInterface:: |
public | function | Gets the ID of the type of the entity. | 1 |
EntityInterface:: |
public | function | Gets the original ID. | 1 |
EntityInterface:: |
public | function | Gets a typed data object for this entity object. | 1 |
EntityInterface:: |
public | function | Indicates if a link template exists for a given key. | 1 |
EntityInterface:: |
public | function | Gets the identifier. | 1 |
EntityInterface:: |
public | function | Determines whether the entity is new. | 1 |
EntityInterface:: |
public | function | Gets the label of the entity. | 3 |
EntityInterface:: |
public | function | Gets the language of the entity. | 1 |
EntityInterface:: |
public static | function | Loads an entity. | 1 |
EntityInterface:: |
public static | function | Loads one or more entities. | 1 |
EntityInterface:: |
public | function | Acts on a created entity before hooks are invoked. | 1 |
EntityInterface:: |
public static | function | Acts on loaded entities. | 2 |
EntityInterface:: |
public static | function | Changes the values of an entity before it is created. | 4 |
EntityInterface:: |
public | function | Acts on an entity before the presave hook is invoked. | 8 |
EntityInterface:: |
public | function | Gets a list of entities referenced by this entity. | 2 |
EntityInterface:: |
public | function | Saves an entity permanently. | 3 |
EntityInterface:: |
public | function | Sets the original ID. | 1 |
EntityInterface:: |
public | function | Gets an array of all property values. | 2 |
EntityInterface:: |
public | function | Generates the HTML for a link to this entity. | 1 |
EntityInterface:: |
public | function | Gets the URL object for the entity. | 1 |
EntityInterface:: |
public | function | Gets a list of URI relationships supported by this entity. | 1 |
EntityInterface:: |
public | function | Gets the entity UUID (Universally Unique Identifier). | 1 |
EntityPublishedTrait:: |
public | function | ||
EntityPublishedTrait:: |
public static | function | Returns an array of base field definitions for publishing status. | |
EntityPublishedTrait:: |
public | function | ||
EntityPublishedTrait:: |
public | function | ||
FieldableEntityInterface:: |
public static | function | Provides field definitions for a specific bundle. | 2 |
FieldableEntityInterface:: |
public | function | Gets a field item list. | |
FieldableEntityInterface:: |
public | function | Gets the definition of a contained field. | |
FieldableEntityInterface:: |
public | function | Gets an array of field definitions of all contained fields. | |
FieldableEntityInterface:: |
public | function | Gets an array of all field item lists. | |
FieldableEntityInterface:: |
public | function | Gets an array of field item lists for translatable fields. | |
FieldableEntityInterface:: |
public | function | Determines whether the entity has a field with the given name. | |
FieldableEntityInterface:: |
public | function | Checks whether entity validation is required before saving the entity. | |
FieldableEntityInterface:: |
public | function | Reacts to changes to a field. | |
FieldableEntityInterface:: |
public | function | Sets a field value. | |
FieldableEntityInterface:: |
public | function | Sets whether entity validation is required before saving the entity. | |
FieldableEntityInterface:: |
public | function | Validates the currently set values. | 1 |
RefinableCacheableDependencyInterface:: |
public | function | Adds a dependency on an object: merges its cacheability metadata. | |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache contexts. | |
RefinableCacheableDependencyInterface:: |
public | function | Adds cache tags. | |
RefinableCacheableDependencyInterface:: |
public | function | Merges the maximum age (in seconds) with the existing maximum age. | |
RefinableDependentAccessTrait:: |
protected | property | The access dependency. | |
RefinableDependentAccessTrait:: |
public | function | ||
RefinableDependentAccessTrait:: |
public | function | ||
RefinableDependentAccessTrait:: |
public | function | ||
RevisionableInterface:: |
public | function | Gets the loaded Revision ID of the entity. | |
RevisionableInterface:: |
public | function | Gets the revision identifier of the entity. | |
RevisionableInterface:: |
public | function | Checks if this entity is the default revision. | |
RevisionableInterface:: |
public | function | Checks if this entity is the latest revision. | |
RevisionableInterface:: |
public | function | Determines whether a new revision should be created on save. | |
RevisionableInterface:: |
public | function | Enforces an entity to be saved as a new revision. | |
RevisionableInterface:: |
public | function | Updates the loaded Revision ID with the revision ID. | |
RevisionableInterface:: |
public | function | Checks whether the entity object was a default revision when it was saved. | |
RevisionLogEntityTrait:: |
abstract public | function | Gets the entity type definition. | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionCreationTime(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUser(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::getRevisionUserId(). | |
RevisionLogEntityTrait:: |
public static | function | Provides revision-related base field definitions for an entity type. | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionCreationTime(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUser(). | |
RevisionLogEntityTrait:: |
public | function | Implements \Drupal\Core\Entity\RevisionLogInterface::setRevisionUserId(). | |
SynchronizableInterface:: |
public | function | Returns whether this entity is being changed as part of a synchronization. | |
SynchronizableInterface:: |
public | function | Sets the status of the synchronization flag. | |
TranslatableInterface:: |
public | function | Adds a new translation to the translatable object. | |
TranslatableInterface:: |
public | function | Gets a translation of the data. | |
TranslatableInterface:: |
public | function | Returns the languages the data is translated to. | |
TranslatableInterface:: |
public | function | Returns the translatable object in the language it was created. | |
TranslatableInterface:: |
public | function | Checks there is a translation for the given language code. | |
TranslatableInterface:: |
public | function | Determines if the current translation of the entity has unsaved changes. | |
TranslatableInterface:: |
public | function | Checks whether the translation is the default one. | |
TranslatableInterface:: |
public | function | Checks whether the translation is new. | |
TranslatableInterface:: |
public | function | Returns the translation support status. | |
TranslatableInterface:: |
public | function | Removes the translation identified by the given language code. | |
TranslatableRevisionableInterface:: |
public | function | Checks if untranslatable fields should affect only the default translation. | |
TranslatableRevisionableInterface:: |
public | function | Checks whether this is the latest revision affecting this translation. | |
TranslatableRevisionableInterface:: |
public | function | Checks whether the current translation is affected by the current revision. | |
TranslatableRevisionableInterface:: |
public | function | Checks if the revision translation affected flag value has been enforced. | |
TranslatableRevisionableInterface:: |
public | function | Marks the current revision translation as affected. | |
TranslatableRevisionableInterface:: |
public | function | Enforces the revision translation affected flag value. |