X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fblock_content%2Fsrc%2FEntity%2FBlockContent.php;h=1037beeef52cf8e67a63e427f9c6764a9ef4de0b;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=9d0bf743b23d4d8dbb823433fffdd509df816747;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/block_content/src/Entity/BlockContent.php b/web/core/modules/block_content/src/Entity/BlockContent.php index 9d0bf743b..1037beeef 100644 --- a/web/core/modules/block_content/src/Entity/BlockContent.php +++ b/web/core/modules/block_content/src/Entity/BlockContent.php @@ -2,8 +2,8 @@ namespace Drupal\block_content\Entity; -use Drupal\Core\Entity\ContentEntityBase; -use Drupal\Core\Entity\EntityChangedTrait; +use Drupal\block_content\Access\RefinableDependentAccessTrait; +use Drupal\Core\Entity\EditorialContentEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; @@ -16,6 +16,13 @@ use Drupal\user\UserInterface; * @ContentEntityType( * id = "block_content", * label = @Translation("Custom block"), + * label_collection = @Translation("Custom blocks"), + * label_singular = @Translation("custom block"), + * label_plural = @Translation("custom blocks"), + * label_count = @PluralTranslation( + * singular = "@count custom block", + * plural = "@count custom blocks", + * ), * bundle_label = @Translation("Custom block type"), * handlers = { * "storage" = "Drupal\Core\Entity\Sql\SqlContentEntityStorage", @@ -42,6 +49,7 @@ use Drupal\user\UserInterface; * "delete-form" = "/block/{block_content}/delete", * "edit-form" = "/block/{block_content}", * "collection" = "/admin/structure/block/block-content", + * "create" = "/block", * }, * translatable = TRUE, * entity_keys = { @@ -50,7 +58,13 @@ use Drupal\user\UserInterface; * "bundle" = "type", * "label" = "info", * "langcode" = "langcode", - * "uuid" = "uuid" + * "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", @@ -62,9 +76,9 @@ use Drupal\user\UserInterface; * caching. * See https://www.drupal.org/node/2284917#comment-9132521 for more information. */ -class BlockContent extends ContentEntityBase implements BlockContentInterface { +class BlockContent extends EditorialContentEntityBase implements BlockContentInterface { - use EntityChangedTrait; + use RefinableDependentAccessTrait; /** * The theme the block is being created in. @@ -107,7 +121,9 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); - static::invalidateBlockPluginCache(); + if ($this->isReusable() || (isset($this->original) && $this->original->isReusable())) { + static::invalidateBlockPluginCache(); + } } /** @@ -115,7 +131,14 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { */ public static function postDelete(EntityStorageInterface $storage, array $entities) { parent::postDelete($storage, $entities); - static::invalidateBlockPluginCache(); + /** @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; + } + } } /** @@ -168,6 +191,8 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { $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.')) @@ -181,41 +206,18 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { ->setDisplayConfigurable('form', TRUE) ->addConstraint('UniqueField', []); - $fields['revision_log'] = BaseFieldDefinition::create('string_long') - ->setLabel(t('Revision log message')) - ->setDescription(t('The log entry explaining the changes in this revision.')) - ->setRevisionable(TRUE) - ->setDisplayOptions('form', [ - 'type' => 'string_textarea', - 'weight' => 25, - 'settings' => [ - 'rows' => 4, - ], - ]); - $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the custom block was last edited.')) ->setTranslatable(TRUE) ->setRevisionable(TRUE); - $fields['revision_created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Revision create time')) - ->setDescription(t('The time that the current revision was created.')) - ->setRevisionable(TRUE); - - $fields['revision_user'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Revision user')) - ->setDescription(t('The user ID of the author of the current revision.')) - ->setSetting('target_type', 'user') - ->setRevisionable(TRUE); - - $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('Revision translation affected')) - ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.')) - ->setReadOnly(TRUE) - ->setRevisionable(TRUE) - ->setTranslatable(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; } @@ -299,6 +301,27 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { 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. */