You are here

public function FormAlter::entityFormEntityBuild in Layout Builder Restrictions 8.2

Same name in this branch
  1. 8.2 src/Form/FormAlter.php \Drupal\layout_builder_restrictions\Form\FormAlter::entityFormEntityBuild()
  2. 8.2 modules/layout_builder_restrictions_by_region/src/Form/FormAlter.php \Drupal\layout_builder_restrictions_by_region\Form\FormAlter::entityFormEntityBuild()
Same name and namespace in other branches
  1. 8 src/Form/FormAlter.php \Drupal\layout_builder_restrictions\Form\FormAlter::entityFormEntityBuild()

Save allowed blocks & layouts for the given entity view mode.

File

src/Form/FormAlter.php, line 278

Class

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

Namespace

Drupal\layout_builder_restrictions\Form

Code

public function entityFormEntityBuild($entity_type_id, LayoutEntityDisplayInterface $display, &$form, FormStateInterface &$form_state) {
  $third_party_settings = $display
    ->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction');
  $block_restrictions = $this
    ->setAllowedBlocks($form_state);
  $third_party_settings['whitelisted_blocks'] = isset($block_restrictions['whitelisted']) ? $block_restrictions['whitelisted'] : [];
  $third_party_settings['blacklisted_blocks'] = isset($block_restrictions['blacklisted']) ? $block_restrictions['blacklisted'] : [];
  $third_party_settings['restricted_categories'] = $block_restrictions['restricted_categories'];
  $third_party_settings['allowed_layouts'] = $this
    ->setAllowedLayouts($form_state);
  $allowed_block_categories = $this
    ->setAllowedBlockCategories($form_state, $display);

  // Save!
  $display
    ->setThirdPartySetting('layout_builder_restrictions', 'allowed_block_categories', $allowed_block_categories);
  $display
    ->setThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction', $third_party_settings);
}