You are here

protected function AllowedBlocksForm::getBlockDefault in Layout Builder Restrictions 8.2

Business logic to set category to 'all', 'whitelisted' or 'blacklisted'.

Parameters

string $block_id: The Drupal block ID.

string $category: The block's category.

mixed $temp_data: The data stored between AJAX submits or null.

Return value

bool Whether or not the block is stored in the restriction type.

1 call to AllowedBlocksForm::getBlockDefault()
AllowedBlocksForm::buildForm in modules/layout_builder_restrictions_by_region/src/Form/AllowedBlocksForm.php
Form constructor.

File

modules/layout_builder_restrictions_by_region/src/Form/AllowedBlocksForm.php, line 444

Class

AllowedBlocksForm
Provides form for designating allowed blocks.

Namespace

Drupal\layout_builder_restrictions_by_region\Form

Code

protected function getBlockDefault($block_id, $category, $temp_data) {

  // Attempt to retrieve default value from tempStore, then from config.
  if (!is_null($temp_data)) {
    if (isset($temp_data[$category]['restrictions'])) {
      return in_array($block_id, array_keys($temp_data[$category]['restrictions']));
    }
    else {
      return FALSE;
    }
  }
  else {
    if (isset($this->whitelistedBlocks[$category])) {
      return in_array($block_id, $this->whitelistedBlocks[$category]);
    }
    if (isset($this->blacklistedBlocks[$category])) {
      return in_array($block_id, $this->blacklistedBlocks[$category]);
    }
    else {
      return FALSE;
    }
  }
  return FALSE;
}