You are here

public function FormAlter::entityFormEntityBuild in Dashboards with Layout Builder 2.0.x

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

File

src/Form/FormAlter.php, line 281

Class

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

Namespace

Drupal\dashboards\Form

Code

public function entityFormEntityBuild($entity_type_id, Dashboard $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);
}