class BlockContentSelection

Provides specific selection control for the block_content entity type.

Attributes

#[EntityReferenceSelection(id: "default:block_content", label: new TranslatableMarkup("Block content selection"), group: "default", weight: 1, entity_types: [ "block_content", ])]

Hierarchy

Expanded class hierarchy of BlockContentSelection

1 file declares its use of BlockContentSelection
BlockContentHooks.php in core/modules/block_content/src/Hook/BlockContentHooks.php

File

core/modules/block_content/src/Plugin/EntityReferenceSelection/BlockContentSelection.php, line 15

Namespace

Drupal\block_content\Plugin\EntityReferenceSelection
View source
class BlockContentSelection extends DefaultSelection {
  
  /**
   * {@inheritdoc}
   */
  protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
    $query = parent::buildEntityQuery($match, $match_operator);
    // Only reusable blocks should be able to be referenced.
    $query->condition('reusable', TRUE);
    return $query;
  }
  
  /**
   * {@inheritdoc}
   */
  public function validateReferenceableNewEntities(array $entities) {
    $entities = parent::validateReferenceableNewEntities($entities);
    // Mirror the conditions checked in buildEntityQuery().
    return array_filter($entities, static fn(BlockContentInterface $blockContent) => $blockContent->isReusable());
  }

}

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