You are here

public function Categories::getReferenceableBlockDefinitions in Block field 8

Returns filtered block definitions based on plugin settings.

Return value

array An array of filtered block definitions.

Overrides BlockFieldSelectionInterface::getReferenceableBlockDefinitions

File

src/Plugin/block_field/BlockFieldSelection/Categories.php, line 70

Class

Categories
Provides a 'categories' BlockFieldSection.

Namespace

Drupal\block_field\Plugin\block_field\BlockFieldSelection

Code

public function getReferenceableBlockDefinitions() {
  $block_field_manager = \Drupal::service('block_field.manager');
  $definitions = $block_field_manager
    ->getBlockDefinitions();
  if (!empty($this
    ->getConfiguration()['categories'])) {
    $categories = array_filter($this
      ->getConfiguration()['categories']);
    $definitions = array_filter($definitions, function ($definition, $key) use ($categories) {
      return isset($categories[(string) $definition['category']]);
    }, ARRAY_FILTER_USE_BOTH);
  }
  return $definitions;
}