function BlockContent::getDerivativeDefinitions

Same name and namespace in other branches
  1. 9 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent::getDerivativeDefinitions()
  2. 8.9.x core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent::getDerivativeDefinitions()
  3. 10 core/modules/block_content/src/Plugin/Derivative/BlockContent.php \Drupal\block_content\Plugin\Derivative\BlockContent::getDerivativeDefinitions()

Overrides DeriverBase::getDerivativeDefinitions

File

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

Class

BlockContent
Retrieves block plugin definitions for all content blocks.

Namespace

Drupal\block_content\Plugin\Derivative

Code

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);
}

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