class BlockContent

Same name in this branch
  1. 11.x core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
  2. 11.x core/modules/block_content/src/Plugin/views/wizard/BlockContent.php \Drupal\block_content\Plugin\views\wizard\BlockContent
Same name in other branches
  1. 9 core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
  2. 9 core/modules/block_content/src/Plugin/views/wizard/BlockContent.php \Drupal\block_content\Plugin\views\wizard\BlockContent
  3. 9 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent
  4. 8.9.x core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
  5. 8.9.x core/modules/block_content/src/Plugin/views/wizard/BlockContent.php \Drupal\block_content\Plugin\views\wizard\BlockContent
  6. 8.9.x core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent
  7. 10 core/modules/block_content/src/Entity/BlockContent.php \Drupal\block_content\Entity\BlockContent
  8. 10 core/modules/block_content/src/Plugin/views/wizard/BlockContent.php \Drupal\block_content\Plugin\views\wizard\BlockContent
  9. 10 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent

Retrieves block plugin definitions for all content blocks.

Attributes

#[ContentEntityType(id: 'block_content', label: new TranslatableMarkup('Content block'), label_collection: new TranslatableMarkup('Content blocks'), label_singular: new TranslatableMarkup('content block'), label_plural: new TranslatableMarkup('content blocks'), render_cache: FALSE, entity_keys: ['id' => 'id', 'revision' => 'revision_id', 'bundle' => 'type', 'label' => 'info', 'langcode' => 'langcode', 'uuid' => 'uuid', 'published' => 'status'], handlers: ['storage' => SqlContentEntityStorage::class, 'storage_schema' => BlockContentStorageSchema::class, 'access' => BlockContentAccessControlHandler::class, 'list_builder' => BlockContentListBuilder::class, 'view_builder' => BlockContentViewBuilder::class, 'views_data' => BlockContentViewsData::class, 'form' => ['add' => BlockContentForm::class, 'edit' => BlockContentForm::class, 'delete' => BlockContentDeleteForm::class, 'default' => BlockContentForm::class, 'revision-delete' => RevisionDeleteForm::class, 'revision-revert' => RevisionRevertForm::class], 'route_provider' => ['revision' => RevisionHtmlRouteProvider::class], 'translation' => BlockContentTranslationHandler::class], 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'], admin_permission: 'administer block content', collection_permission: 'access block library', bundle_entity_type: 'block_content_type', bundle_label: new TranslatableMarkup('Block type'), base_table: 'block_content', data_table: 'block_content_field_data', revision_table: 'block_content_revision', revision_data_table: 'block_content_field_revision', translatable: TRUE, show_revision_ui: TRUE, label_count: ['singular' => '@count content block', 'plural' => '@count content blocks'], field_ui_base_route: 'entity.block_content_type.edit_form', revision_metadata_keys: ['revision_user' => 'revision_user', 'revision_created' => 'revision_created', 'revision_log_message' => 'revision_log'])]
#[ViewsWizard(id: 'block_content', title: new TranslatableMarkup('Content Block'), base_table: 'block_content_field_data')]

Hierarchy

Expanded class hierarchy of BlockContent

2 files declare their use of BlockContent
BlockContentBlock.php in core/modules/block_content/src/Plugin/Block/BlockContentBlock.php
BlockContentDeriverTest.php in core/modules/block_content/tests/src/Kernel/BlockContentDeriverTest.php

File

core/modules/block_content/src/Plugin/Derivative/BlockContent.php, line 13

Namespace

Drupal\block_content\Plugin\Derivative
View source
class BlockContent extends DeriverBase implements ContainerDeriverInterface {
    
    /**
     * The content block storage.
     *
     * @var \Drupal\Core\Entity\EntityStorageInterface
     */
    protected $blockContentStorage;
    
    /**
     * Constructs a BlockContent object.
     *
     * @param \Drupal\Core\Entity\EntityStorageInterface $block_content_storage
     *   The content block storage.
     */
    public function __construct(EntityStorageInterface $block_content_storage) {
        $this->blockContentStorage = $block_content_storage;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, $base_plugin_id) {
        $entity_type_manager = $container->get('entity_type.manager');
        return new static($entity_type_manager->getStorage('block_content'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getDerivativeDefinitions($base_plugin_definition) {
        $block_contents = $this->blockContentStorage
            ->loadByProperties([
            'reusable' => TRUE,
        ]);
        // Reset the discovered definitions.
        $this->derivatives = [];
        
        /** @var \Drupal\block_content\Entity\BlockContent $block_content */
        foreach ($block_contents as $block_content) {
            $this->derivatives[$block_content->uuid()] = $base_plugin_definition;
            $this->derivatives[$block_content->uuid()]['admin_label'] = $block_content->label() ?? $block_content->type->entity
                ->label() . ': ' . $block_content->id();
            $this->derivatives[$block_content->uuid()]['config_dependencies']['content'] = [
                $block_content->getConfigDependencyName(),
            ];
        }
        return parent::getDerivativeDefinitions($base_plugin_definition);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
BlockContent::$blockContentStorage protected property The content block storage.
BlockContent::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
BlockContent::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
BlockContent::__construct public function Constructs a BlockContent object.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.