Verified Commit 1c218641 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3379725 by Wim Leers, phenaproxima, narendraR, alexpott, quietone,...

Issue #3379725 by Wim Leers, phenaproxima, narendraR, alexpott, quietone, borisson_, tim.plunkett: Make Block config entities fully validatable
parent dca3ac8c
Loading
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -427,12 +427,16 @@ config_entity:
      requiredKey: false
      type: _core_config_info

# This applies to all blocks that have no additional settings of their own.
block.settings.*:
  type: block_settings
  constraints:
    FullyValidatable: ~

block_settings:
  type: mapping
  label: 'Block settings'
  # This is intentionally not marked as fully validatable: each `type: block.settings.SOMETHING` must do that.
  mapping:
    id:
      type: string
@@ -441,21 +445,17 @@ block_settings:
      type: label
      label: 'Description'
    label_display:
      type: string
      type: label
      label: 'Display title'
    provider:
      type: string
      label: 'Provider'
    status:
      type: boolean
      label: 'Status'
    info:
      type: label
      label: 'Admin info'
    view_mode:
      type: string
      label: 'View mode'
      label: 'Provider of this block plugin'
      constraints:
        NotBlank: []
        ExtensionName: []
        ExtensionExists: module
    context_mapping:
      requiredKey: false
      type: sequence
      label: 'Context assignments'
      sequence:
+18 −0
Original line number Diff line number Diff line
@@ -5,6 +5,9 @@
 * Post update functions for Block.
 */

use Drupal\block\BlockInterface;
use Drupal\Core\Config\Entity\ConfigEntityUpdater;

/**
 * Implements hook_removed_post_updates().
 */
@@ -16,3 +19,18 @@ function block_removed_post_updates() {
    'block_post_update_replace_node_type_condition' => '10.0.0',
  ];
}

/**
 * Ensures that all block weights are integers.
 */
function block_post_update_make_weight_integer(array &$sandbox = []): void {
  \Drupal::classResolver(ConfigEntityUpdater::class)
    ->update($sandbox, 'block', function (BlockInterface $block): bool {
      $weight = $block->getWeight();
      if (!is_int($weight)) {
        $block->setWeight($weight);
        return TRUE;
      }
      return FALSE;
    });
}
+11 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
block.block.*:
  type: config_entity
  label: 'Block'
  constraints:
    FullyValidatable: ~
  mapping:
    id:
      type: machine_name
@@ -17,13 +19,22 @@ block.block.*:
    theme:
      type: string
      label: 'Theme'
      constraints:
        NotBlank: []
        ExtensionName: []
        ExtensionExists: theme
    region:
      type: string
      label: 'Region'
      constraints:
        NotBlank: []
        Callback: ['\Drupal\block\Entity\Block', validateRegion]
    weight:
      type: weight
      label: 'Weight'
    provider:
      # @todo Deprecate this from config schema and remove it from the `config_export` definition in https://www.drupal.org/project/drupal/issues/3426278
      nullable: true
      type: string
      label: 'Provider'
    plugin:
+8 −1
Original line number Diff line number Diff line
@@ -96,7 +96,14 @@ process:
          right: sidebar
    # If mapping fails, put the block in the content region.
    default_value: content
  weight: weight
  weight:
    -
      plugin: get
      source: weight
    -
      # Block weights must be integers.
      plugin: callback
      callable: intval
  settings:
    plugin: block_settings
    source:
+8 −1
Original line number Diff line number Diff line
@@ -117,7 +117,14 @@ process:
          sidebar_first: 'sidebar_first'
    # If mapping fails, put the block in the content region.
    default_value: content
  weight: weight
  weight:
    -
      plugin: get
      source: weight
    -
      # Block weights must be integers.
      plugin: callback
      callable: intval
  settings:
    plugin: block_settings
    source:
Loading