You are here

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

Helper function to prepare saved block definition categories.

Return value

array An array of block category names or empty.

1 call to FormAlter::setAllowedBlockCategories()
FormAlter::entityFormEntityBuild in src/Form/FormAlter.php
Save allowed blocks & layouts for the given entity view mode.

File

src/Form/FormAlter.php, line 363

Class

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

Namespace

Drupal\dashboards\Form

Code

protected function setAllowedBlockCategories(FormStateInterface $form_state, Dashboard $display) {

  // Set default for allowed block categories.
  $block_category_default = $form_state
    ->getValue([
    'layout_builder_restrictions',
    'allowed_block_categories',
  ]);
  if ($block_category_default == 'restricted') {

    // Create a whitelist of categories whose blocks should be allowed.
    // Newly available categories' blocks not in this list will be
    // disallowed.
    $allowed_block_categories = array_keys($this
      ->getBlockDefinitions($display));
  }
  else {

    // The UI choice indicates that all newly available categories'
    // blocks should be allowed by default. Represent this in the schema
    // as an empty array.
    $allowed_block_categories = [];
  }
  return $allowed_block_categories;
}