You are here

protected function FormAlter::getBlockDefinitions in Dashboards with Layout Builder 2.0.x

Gets block definitions appropriate for an entity display.

Parameters

\Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $display: The entity display being edited.

Return value

array[] Keys are category names, and values are arrays of which the keys are plugin IDs and the values are plugin definitions.

2 calls to FormAlter::getBlockDefinitions()
FormAlter::alterEntityViewDisplayForm in src/Form/FormAlter.php
The actual form elements.
FormAlter::setAllowedBlockCategories in src/Form/FormAlter.php
Helper function to prepare saved block definition categories.

File

src/Form/FormAlter.php, line 394

Class

FormAlter
Supplement form UI to add setting for which blocks & layouts are available.

Namespace

Drupal\dashboards\Form

Code

protected function getBlockDefinitions() {
  $definitions = $this
    ->blockManager()
    ->getDefinitions();

  /**
   * @todo Provide a alter function for more providers.
   */
  $allowedProvider = [
    'system',
    'views',
    'dashboard',
  ];
  foreach ($definitions as $key => $definition) {
    if (!in_array($definition['provider'], $allowedProvider)) {
      unset($definitions[$key]);
    }
  }
  $grouped_definitions = $this
    ->getDefinitionsByUntranslatedCategory($definitions);

  // Create a new category of block_content blocks that meet the context.
  foreach ($grouped_definitions as $category => $data) {
    if (empty($data['definitions'])) {
      unset($grouped_definitions[$category]);
    }
  }
  ksort($grouped_definitions);
  return $grouped_definitions;
}