You are here

protected function FormAlter::setAllowedBlockCategories in Layout Builder Restrictions 8.2

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 360

Class

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

Namespace

Drupal\layout_builder_restrictions\Form

Code

protected function setAllowedBlockCategories(FormStateInterface $form_state, LayoutEntityDisplayInterface $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;
}