Commit 93f6cdfe authored by Lucas Cruz's avatar Lucas Cruz Committed by Mark Fullmer
Browse files

Issue #3179983 by diegors, mark_fullmer, Joel Guerreiro Borghi Filho, lucassc,...

Issue #3179983 by diegors, mark_fullmer, Joel Guerreiro Borghi Filho, lucassc, elber, sophiavs, beatrizrodrigues: Replace remaining language of 'whitelist'/'blacklist' in Layout Builder Restrictions module
parent 89f6ef4c
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -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:

@@ -65,13 +65,21 @@ additional plugins have been added, site builders can control which plugins are
active at `/admin/config/content/layout-builder-restrictions`

### Disambiguation: block types, individual custom blocks, and inline blocks
This module provides separate restrictions for "CUSTOM BLOCK TYPES", "CUSTOM BLOCKS", and "INLINE BLOCKS."
This module provides separate restrictions for "CUSTOM BLOCK TYPES",
"CUSTOM BLOCKS", and "INLINE BLOCKS."

Restrictions for "CUSTOM BLOCK TYPES" will prevent *any* individual blocks of a restricted type, created through the block library, from being placed.
Restrictions for "CUSTOM BLOCK TYPES" will prevent *any* individual blocks of a
restricted type, created through the block library, from being placed.

If, on the other hand, the "CUSTOM BLOCKS" restriction section is used -- i.e., restrictions are placed on *specific instances* of blocks -- this restriction will take precedence over those defined in "CUSTOM BLOCK TYPES." For most site configurations, you will likely use either block type-level restrictions or individual block restrictions, but not both.
If, on the other hand, the "CUSTOM BLOCKS" restriction section is used -- i.e.,
restrictions are placed on *specific instances* of blocks -- this restriction
will take precedence over those defined in "CUSTOM BLOCK TYPES." For most site
configurations, you will likely use either block type-level restrictions or
individual block restrictions, but not both.

Separately, the "INLINE BLOCKS" section regulates which block types are restricted from being created inline (i.e., on the `Layout` tab of a Layout Builder-enabled entity).
Separately, the "INLINE BLOCKS" section regulates which block types are
restricted from being created inline (i.e., on the `Layout` tab of a Layout
Builder-enabled entity).

ADD NEW RESTRICTIONS VIA PLUGIN (DEVELOPERS)
--------------------------------------------
+6 −6
Original line number Diff line number Diff line
@@ -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'
+33 −1
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ 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'
@@ -155,3 +155,35 @@ function layout_builder_restrictions_update_8212(&$sandbox) {

  $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count'];
}

/**
 * Relocate 'whitelisted_' and 'blacklisted' to 'allowlisted' and 'denylisted'.
 */
function layout_builder_restrictions_update_8213(&$sandbox) {
  // When upgrading to 2.14, configuration for 'whitelisted_blocks'
  // is relocated to 'allowlisted_blocks' and 'blacklisted_blocks' to'
  // 'denylisted_blocks'. See #3179983.
  $config_factory = \Drupal::configFactory();

  if (!isset($sandbox['count'])) {
    $sandbox['ids'] = $config_factory->listAll('core.entity_view_display.');
    $sandbox['count'] = count($sandbox['ids']);
  }

  $ids = array_splice($sandbox['ids'], 0, 50);
  foreach ($ids as $id) {
    $display = $config_factory->getEditable($id);
    if ($display->get('third_party_settings.layout_builder_restrictions')) {
      $allowed_blocks_by_category_whitelisted = $display->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.whitelisted_blocks');
      $allowed_blocks_by_category_blacklisted = $display->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.blacklisted_blocks');
      $display
        ->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.whitelisted_blocks')
        ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.allowlisted_blocks', $allowed_blocks_by_category_whitelisted)
        ->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.blacklisted_blocks')
        ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction.denylisted_blocks', $allowed_blocks_by_category_blacklisted)
        ->save();
    }
  }

  $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count'];
}
+2 −3
Original line number Diff line number Diff line
@@ -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:
@@ -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:
@@ -50,4 +50,3 @@ layout_builder_restrictions.entity_view_mode_restriction_by_region:
          sequence:
            type: string
            label: 'Region restrictions'
+38 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains update functions for Layout Builder Restrictions by Region.
 */

/**
 * Relocate 'whitelisted_' and 'blacklisted' to 'allowlisted' and 'denylisted'.
 */
function layout_builder_restrictions_by_region_update_8201(&$sandbox) {
  // When upgrading to 2.14, configuration for 'whitelisted_blocks'
  // is relocated to 'allowlisted_blocks' and 'blacklisted_blocks' to'
  // 'denylisted_blocks'. See #3179983.
  $config_factory = \Drupal::configFactory();

  if (!isset($sandbox['count'])) {
    $sandbox['ids'] = $config_factory->listAll('core.entity_view_display.');
    $sandbox['count'] = count($sandbox['ids']);
  }

  $ids = array_splice($sandbox['ids'], 0, 50);
  foreach ($ids as $id) {
    $display = $config_factory->getEditable($id);
    if ($display->get('third_party_settings.layout_builder_restrictions')) {
      $allowed_blocks_by_category_whitelisted = $display->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction_by_region.whitelisted_blocks');
      $allowed_blocks_by_category_blacklisted = $display->get('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction_by_region.blacklisted_blocks');
      $display
        ->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction_by_region.whitelisted_blocks')
        ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction_by_region.allowlisted_blocks', $allowed_blocks_by_category_whitelisted)
        ->clear('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction_by_region.blacklisted_blocks')
        ->set('third_party_settings.layout_builder_restrictions.entity_view_mode_restriction_by_region.denylisted_blocks', $allowed_blocks_by_category_blacklisted)
        ->save();
    }
  }

  $sandbox['#finished'] = empty($sandbox['ids']) ? 1 : ($sandbox['count'] - count($sandbox['ids'])) / $sandbox['count'];
}
Loading