You are here

public function PluginHelperTrait::categoryIsRestricted in Layout Builder Restrictions 8.2

Helper function to check the default block category whitelist.

Parameters

string $category: The identifier of the category.

array $allowed_block_categories: The entity view mode's allowed block categories.

Return value

bool Whether or not the category is restricted.

2 calls to PluginHelperTrait::categoryIsRestricted()
EntityViewModeRestriction::alterBlockDefinitions in src/Plugin/LayoutBuilderRestriction/EntityViewModeRestriction.php
Alter the block definitions.
EntityViewModeRestrictionByRegion::alterBlockDefinitions in modules/layout_builder_restrictions_by_region/src/Plugin/LayoutBuilderRestriction/EntityViewModeRestrictionByRegion.php
Alter the block definitions.

File

src/Traits/PluginHelperTrait.php, line 157

Class

PluginHelperTrait
Methods to help Layout Builder Restrictions plugins.

Namespace

Drupal\layout_builder_restrictions\Traits

Code

public function categoryIsRestricted($category, array $allowed_block_categories) {
  if (!empty($allowed_block_categories)) {

    // There is no explicit indication whether the blocks from
    // this category should be restricted. Check the default whitelist.
    if (!in_array($category, $allowed_block_categories)) {

      // This block's category has not been whitelisted.
      return TRUE;
    }
  }
  return FALSE;
}