Loading README.md +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ INSTALLATION & MANAGEMENT IN THE UI 2. Expand the "Layout options" fieldset and choose either "Blocks available for placement" or "Layouts available for placement". Initially, all blocks and layouts are available, as would be the case if the module were not enabled. For blocks, each "provider" is listed, and can either be whitelisted to allow For blocks, each "provider" is listed, and can either be allowlisted to allow all blocks from the given provider, or restricted with the "Choose specific..." option: Loading config/schema/layout_builder_restrictions.schema.yml +6 −6 Original line number Diff line number Diff line Loading @@ -14,21 +14,21 @@ layout_builder_restrictions.entity_view_mode_restriction: sequence: type: string label: 'Layout ID' blacklisted_blocks: denylisted_blocks: type: sequence label: 'Blacklisted blocks by category' label: 'Denylisted blocks by category' sequence: type: sequence label: 'Blacklisted blocks' label: 'Denylisted blocks' sequence: type: string label: 'Block ID' whitelisted_blocks: allowlisted_blocks: type: sequence label: 'Whitelisted blocks by category' label: 'Allowlisted blocks by category' sequence: type: sequence label: 'Whitelisted blocks' label: 'Allowlisted blocks' sequence: type: string label: 'Block ID' Loading layout_builder_restrictions.install +5 −5 Original line number Diff line number Diff line Loading @@ -126,12 +126,12 @@ function layout_builder_restrictions_update_8211(&$sandbox) { } /** * Relocate 'allowed_blocks' to 'whitelisted_blocks'. * Relocate 'allowed_blocks' to 'allowlisted_blocks'. */ function layout_builder_restrictions_update_8212(&$sandbox) { // When upgrading to 2.6, configuration for 'allowed_blocks' // is relocated to 'whitelisted_blocks' to distinguish from newly available // 'blacklisted_blocks' (which will default to an empty array for existing // is relocated to 'allowlisted_blocks' to distinguish from newly available // 'denylisted_blocks' (which will default to an empty array for existing // sites). $config_factory = \Drupal::configFactory(); Loading @@ -147,8 +147,8 @@ function layout_builder_restrictions_update_8212(&$sandbox) { $allowed_blocks_by_category = $display->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowed_blocks'); $display ->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowed_blocks') ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.whitelisted_blocks', $allowed_blocks_by_category) ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.blacklisted_blocks', []) ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowlisted_blocks', $allowed_blocks_by_category) ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.denylisted_blocks', []) ->save(); } } Loading modules/layout_builder_restrictions_by_region/config/schema/layout_builder_restrictions_by_region.schema.yml +2 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ layout_builder_restrictions.entity_view_mode_restriction_by_region: sequence: type: string label: 'Layout ID' whitelisted_blocks: allowlisted_blocks: type: sequence label: 'Layouts to be restricted' sequence: Loading @@ -23,7 +23,7 @@ layout_builder_restrictions.entity_view_mode_restriction_by_region: sequence: type: string label: Category blacklisted_blocks: denylisted_blocks: type: sequence label: 'Layouts to be restricted' sequence: Loading modules/layout_builder_restrictions_by_region/src/Form/AllowedBlocksForm.php +21 −21 Original line number Diff line number Diff line Loading @@ -84,18 +84,18 @@ class AllowedBlocksForm extends FormBase { protected $tempData; /** * An array of whitelisted blocks, by category. * An array of allowlisted blocks, by category. * * @var array */ protected $whitelistedBlocks; protected $allowlistedBlocks; /** * An array of blacklisted blocks, by category. * An array of denylisted blocks, by category. * * @var array */ protected $blacklistedBlocks; protected $denylistedBlocks; /** * An array of restricted block categories. Loading Loading @@ -159,8 +159,8 @@ class AllowedBlocksForm extends FormBase { $this->regionId = $current_request->query->get('region_id'); $this->allowedBlockCategories = $display->getThirdPartySetting('layout_builder_restrictions', 'allowed_block_categories', []); $third_party_settings = $display->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction_by_region', []); $this->whitelistedBlocks = (isset($third_party_settings['whitelisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['whitelisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->blacklistedBlocks = (isset($third_party_settings['blacklisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['blacklisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->allowlistedBlocks = (isset($third_party_settings['allowlisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['allowlisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->denylistedBlocks = (isset($third_party_settings['denylisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['denylisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->restrictedCategories = (isset($third_party_settings['restricted_categories'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['restricted_categories'][$this->layoutPluginId][$this->regionId] : []; } Loading Loading @@ -231,8 +231,8 @@ class AllowedBlocksForm extends FormBase { '#options' => [ "all" => $this->t('Allow all existing & new %category blocks.', ['%category' => $data['label']]), "restrict_all" => $this->t('Restrict all existing & new %category blocks.', ['%category' => $data['label']]), "whitelisted" => $this->t('Allow specific %category blocks:', ['%category' => $data['label']]), "blacklisted" => $this->t('Restrict specific %category blocks:', ['%category' => $data['label']]), "allowlisted" => $this->t('Allow specific %category blocks:', ['%category' => $data['label']]), "denylisted" => $this->t('Restrict specific %category blocks:', ['%category' => $data['label']]), ], '#parents' => [ 'allowed_blocks', Loading Loading @@ -336,7 +336,7 @@ class AllowedBlocksForm extends FormBase { foreach ($categories as $category => $category_setting) { $restriction_type = $category_setting['restriction']; $block_restrictions[$category]['restriction_type'] = $restriction_type; if (in_array($restriction_type, ['whitelisted', 'blacklisted'])) { if (in_array($restriction_type, ['allowlisted', 'denylisted'])) { foreach ($category_setting['allowed_blocks'] as $block_id => $block_setting) { if ($block_setting == '1') { // Include only checked blocks. Loading Loading @@ -388,7 +388,7 @@ class AllowedBlocksForm extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) {} /** * Business logic to set category to 'all', 'whitelisted' or 'blacklisted'. * Business logic to set category to 'all', 'allowlisted' or 'denylisted'. * * @param string $category * The block's category. Loading @@ -396,7 +396,7 @@ class AllowedBlocksForm extends FormBase { * The data stored between AJAX submits or null. * * @return string * The value 'all', 'whitelisted', 'blacklisted', or 'restrict_all'. * The value 'all', 'allowlisted', 'denylisted', or 'restrict_all'. */ protected function getCategoryBehavior($category, $temp_data) { // Check whether this is a newly available category that has been Loading @@ -408,18 +408,18 @@ class AllowedBlocksForm extends FormBase { return $temp_data[$category]['restriction_type']; } else { if (isset($this->whitelistedBlocks) && in_array($category, array_keys($this->whitelistedBlocks))) { return "whitelisted"; if (isset($this->allowlistedBlocks) && in_array($category, array_keys($this->allowlistedBlocks))) { return "allowlisted"; } elseif (isset($this->blacklistedBlocks) && in_array($category, array_keys($this->blacklistedBlocks))) { return "blacklisted"; elseif (isset($this->denylistedBlocks) && in_array($category, array_keys($this->denylistedBlocks))) { return "denylisted"; } 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. // use 'allowlisted' to preset this as if all blocks were restricted. return "restrict_all"; } else { Loading @@ -429,7 +429,7 @@ class AllowedBlocksForm extends FormBase { } /** * Business logic to set category to 'all', 'whitelisted' or 'blacklisted'. * Business logic to set category to 'all', 'allowlisted' or 'denylisted'. * * @param string $block_id * The Drupal block ID. Loading @@ -452,11 +452,11 @@ class AllowedBlocksForm extends FormBase { } } else { if (isset($this->whitelistedBlocks[$category])) { return in_array($block_id, $this->whitelistedBlocks[$category]); if (isset($this->allowlistedBlocks[$category])) { return in_array($block_id, $this->allowlistedBlocks[$category]); } if (isset($this->blacklistedBlocks[$category])) { return in_array($block_id, $this->blacklistedBlocks[$category]); if (isset($this->denylistedBlocks[$category])) { return in_array($block_id, $this->denylistedBlocks[$category]); } else { return FALSE; Loading Loading
README.md +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ INSTALLATION & MANAGEMENT IN THE UI 2. Expand the "Layout options" fieldset and choose either "Blocks available for placement" or "Layouts available for placement". Initially, all blocks and layouts are available, as would be the case if the module were not enabled. For blocks, each "provider" is listed, and can either be whitelisted to allow For blocks, each "provider" is listed, and can either be allowlisted to allow all blocks from the given provider, or restricted with the "Choose specific..." option: Loading
config/schema/layout_builder_restrictions.schema.yml +6 −6 Original line number Diff line number Diff line Loading @@ -14,21 +14,21 @@ layout_builder_restrictions.entity_view_mode_restriction: sequence: type: string label: 'Layout ID' blacklisted_blocks: denylisted_blocks: type: sequence label: 'Blacklisted blocks by category' label: 'Denylisted blocks by category' sequence: type: sequence label: 'Blacklisted blocks' label: 'Denylisted blocks' sequence: type: string label: 'Block ID' whitelisted_blocks: allowlisted_blocks: type: sequence label: 'Whitelisted blocks by category' label: 'Allowlisted blocks by category' sequence: type: sequence label: 'Whitelisted blocks' label: 'Allowlisted blocks' sequence: type: string label: 'Block ID' Loading
layout_builder_restrictions.install +5 −5 Original line number Diff line number Diff line Loading @@ -126,12 +126,12 @@ function layout_builder_restrictions_update_8211(&$sandbox) { } /** * Relocate 'allowed_blocks' to 'whitelisted_blocks'. * Relocate 'allowed_blocks' to 'allowlisted_blocks'. */ function layout_builder_restrictions_update_8212(&$sandbox) { // When upgrading to 2.6, configuration for 'allowed_blocks' // is relocated to 'whitelisted_blocks' to distinguish from newly available // 'blacklisted_blocks' (which will default to an empty array for existing // is relocated to 'allowlisted_blocks' to distinguish from newly available // 'denylisted_blocks' (which will default to an empty array for existing // sites). $config_factory = \Drupal::configFactory(); Loading @@ -147,8 +147,8 @@ function layout_builder_restrictions_update_8212(&$sandbox) { $allowed_blocks_by_category = $display->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowed_blocks'); $display ->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowed_blocks') ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.whitelisted_blocks', $allowed_blocks_by_category) ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.blacklisted_blocks', []) ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowlisted_blocks', $allowed_blocks_by_category) ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.denylisted_blocks', []) ->save(); } } Loading
modules/layout_builder_restrictions_by_region/config/schema/layout_builder_restrictions_by_region.schema.yml +2 −2 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ layout_builder_restrictions.entity_view_mode_restriction_by_region: sequence: type: string label: 'Layout ID' whitelisted_blocks: allowlisted_blocks: type: sequence label: 'Layouts to be restricted' sequence: Loading @@ -23,7 +23,7 @@ layout_builder_restrictions.entity_view_mode_restriction_by_region: sequence: type: string label: Category blacklisted_blocks: denylisted_blocks: type: sequence label: 'Layouts to be restricted' sequence: Loading
modules/layout_builder_restrictions_by_region/src/Form/AllowedBlocksForm.php +21 −21 Original line number Diff line number Diff line Loading @@ -84,18 +84,18 @@ class AllowedBlocksForm extends FormBase { protected $tempData; /** * An array of whitelisted blocks, by category. * An array of allowlisted blocks, by category. * * @var array */ protected $whitelistedBlocks; protected $allowlistedBlocks; /** * An array of blacklisted blocks, by category. * An array of denylisted blocks, by category. * * @var array */ protected $blacklistedBlocks; protected $denylistedBlocks; /** * An array of restricted block categories. Loading Loading @@ -159,8 +159,8 @@ class AllowedBlocksForm extends FormBase { $this->regionId = $current_request->query->get('region_id'); $this->allowedBlockCategories = $display->getThirdPartySetting('layout_builder_restrictions', 'allowed_block_categories', []); $third_party_settings = $display->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction_by_region', []); $this->whitelistedBlocks = (isset($third_party_settings['whitelisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['whitelisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->blacklistedBlocks = (isset($third_party_settings['blacklisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['blacklisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->allowlistedBlocks = (isset($third_party_settings['allowlisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['allowlisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->denylistedBlocks = (isset($third_party_settings['denylisted_blocks'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['denylisted_blocks'][$this->layoutPluginId][$this->regionId] : []; $this->restrictedCategories = (isset($third_party_settings['restricted_categories'][$this->layoutPluginId][$this->regionId])) ? $third_party_settings['restricted_categories'][$this->layoutPluginId][$this->regionId] : []; } Loading Loading @@ -231,8 +231,8 @@ class AllowedBlocksForm extends FormBase { '#options' => [ "all" => $this->t('Allow all existing & new %category blocks.', ['%category' => $data['label']]), "restrict_all" => $this->t('Restrict all existing & new %category blocks.', ['%category' => $data['label']]), "whitelisted" => $this->t('Allow specific %category blocks:', ['%category' => $data['label']]), "blacklisted" => $this->t('Restrict specific %category blocks:', ['%category' => $data['label']]), "allowlisted" => $this->t('Allow specific %category blocks:', ['%category' => $data['label']]), "denylisted" => $this->t('Restrict specific %category blocks:', ['%category' => $data['label']]), ], '#parents' => [ 'allowed_blocks', Loading Loading @@ -336,7 +336,7 @@ class AllowedBlocksForm extends FormBase { foreach ($categories as $category => $category_setting) { $restriction_type = $category_setting['restriction']; $block_restrictions[$category]['restriction_type'] = $restriction_type; if (in_array($restriction_type, ['whitelisted', 'blacklisted'])) { if (in_array($restriction_type, ['allowlisted', 'denylisted'])) { foreach ($category_setting['allowed_blocks'] as $block_id => $block_setting) { if ($block_setting == '1') { // Include only checked blocks. Loading Loading @@ -388,7 +388,7 @@ class AllowedBlocksForm extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) {} /** * Business logic to set category to 'all', 'whitelisted' or 'blacklisted'. * Business logic to set category to 'all', 'allowlisted' or 'denylisted'. * * @param string $category * The block's category. Loading @@ -396,7 +396,7 @@ class AllowedBlocksForm extends FormBase { * The data stored between AJAX submits or null. * * @return string * The value 'all', 'whitelisted', 'blacklisted', or 'restrict_all'. * The value 'all', 'allowlisted', 'denylisted', or 'restrict_all'. */ protected function getCategoryBehavior($category, $temp_data) { // Check whether this is a newly available category that has been Loading @@ -408,18 +408,18 @@ class AllowedBlocksForm extends FormBase { return $temp_data[$category]['restriction_type']; } else { if (isset($this->whitelistedBlocks) && in_array($category, array_keys($this->whitelistedBlocks))) { return "whitelisted"; if (isset($this->allowlistedBlocks) && in_array($category, array_keys($this->allowlistedBlocks))) { return "allowlisted"; } elseif (isset($this->blacklistedBlocks) && in_array($category, array_keys($this->blacklistedBlocks))) { return "blacklisted"; elseif (isset($this->denylistedBlocks) && in_array($category, array_keys($this->denylistedBlocks))) { return "denylisted"; } 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. // use 'allowlisted' to preset this as if all blocks were restricted. return "restrict_all"; } else { Loading @@ -429,7 +429,7 @@ class AllowedBlocksForm extends FormBase { } /** * Business logic to set category to 'all', 'whitelisted' or 'blacklisted'. * Business logic to set category to 'all', 'allowlisted' or 'denylisted'. * * @param string $block_id * The Drupal block ID. Loading @@ -452,11 +452,11 @@ class AllowedBlocksForm extends FormBase { } } else { if (isset($this->whitelistedBlocks[$category])) { return in_array($block_id, $this->whitelistedBlocks[$category]); if (isset($this->allowlistedBlocks[$category])) { return in_array($block_id, $this->allowlistedBlocks[$category]); } if (isset($this->blacklistedBlocks[$category])) { return in_array($block_id, $this->blacklistedBlocks[$category]); if (isset($this->denylistedBlocks[$category])) { return in_array($block_id, $this->denylistedBlocks[$category]); } else { return FALSE; Loading