protected function AllowedBlocksForm::getCategoryBehavior in Layout Builder Restrictions 8.2
Business logic to set category to 'all', 'whitelisted' or 'blacklisted'.
Parameters
string $category: The block's category.
mixed $temp_data: The data stored between AJAX submits or null.
Return value
string The value 'all', 'whitelisted', 'blacklisted', or 'restrict_all'.
1 call to AllowedBlocksForm::getCategoryBehavior()
- 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 401
Class
- AllowedBlocksForm
- Provides form for designating allowed blocks.
Namespace
Drupal\layout_builder_restrictions_by_region\FormCode
protected function getCategoryBehavior($category, $temp_data) {
// Check whether this is a newly available category that has been
// restricted previously.
$category_is_restricted = !empty($this->allowedBlockCategories) && !in_array($category, $this->allowedBlockCategories);
// Attempt to retrieve default value from tempStore, then from config
// before settings to 'all'.
if (!is_null($temp_data[$category]['restriction_type'])) {
return $temp_data[$category]['restriction_type'];
}
else {
if (isset($this->whitelistedBlocks) && in_array($category, array_keys($this->whitelistedBlocks))) {
return "whitelisted";
}
elseif (isset($this->blacklistedBlocks) && in_array($category, array_keys($this->blacklistedBlocks))) {
return "blacklisted";
}
elseif (in_array($category, $this->restrictedCategories)) {
return 'restrict_all';
}
elseif ($category_is_restricted) {
// If there is no configuration, but the category hasn't been 'allowed',
// use 'whitelisted' to preset this as if all blocks were restricted.
return "restrict_all";
}
else {
return 'all';
}
}
}