Fix Block config entity type config schema violations: weight, property

Created on 7 August 2023, over 1 year ago

Problem/Motivation

Discovered in 📌 Configuration schema & required values: add test coverage for `nullable: true` validation support Fixed .

For example:

1) Drupal\Tests\block\Kernel\BlockValidationTest::testInvalidPluginId
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for block.block.test_block with the following errors: 0 [weight] This value should not be null., 1 [provider] This value should not be null.

Steps to reproduce

Run Drupal core's test suite with 📌 Configuration schema & required values: add test coverage for `nullable: true` validation support Fixed applied, and with the lines

    'block.block.*' => [
      // @todo Fix config or tweak schema of `type: block.block.*`.
      // @see block.schema.yml
      'weight' => [
        'This value should not be null.',
      ],
      'provider' => [
        'This value should not be null.',
      ],
    ],

removed from \Drupal\Core\Config\Schema\SchemaCheckTrait::checkConfigSchema().

Proposed resolution

Solution for the example above:

⚠️ … but also wait for the remainder of block.block.* to become validatable? The following property paths are not yet validatable at this time:

  1. region
  2. settings.id
  3. settings.label_display
  4. settings.provider
  5. theme
  6. visibility
  7. weight

Remaining tasks

Fix all of these failures.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

📌 Task
Status

Postponed

Version

11.0 🔥

Component
Block 

Last updated about 3 hours ago

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @wim leers
  • Assigned to wim leers
  • Status changed to Active about 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Repurposing this to add validation constraints; the original issue summary no longer makes sense because the scope/approach of 📌 Configuration schema & required values: add test coverage for `nullable: true` validation support Fixed evolved.

  • Merge request !6938Resolve #3379725 "Validatable block" → (Open) created by wim leers
  • Status changed to Needs work about 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Well this is interesting… AFAICT block.block.*:provider is dead/completely unused, but block.block.*:settings.provider is used.

  • Pipeline finished with Failed
    about 1 year ago
    Total: 533s
    #112765
  • Pipeline finished with Failed
    about 1 year ago
    Total: 551s
    #112849
  • Pipeline finished with Failed
    about 1 year ago
    Total: 487s
    #112863
  • Pipeline finished with Failed
    about 1 year ago
    Total: 489s
    #112873
  • Pipeline finished with Failed
    about 1 year ago
    Total: 546s
    #112879
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Ah, I finally found the explanation for why status, info and view_mode are part of the generic type: block_settings (and hence apply to ALL block plugins!).

    The answer: it's simply an oversight that occurred in #2274175: Block plugin schema should be defined separately from the entity . 😄👍 (\Drupal\block_content\Plugin\Block\BlockContentBlock landed >1 year earlier, but the tight coupling only was removed ~6 months earlier, in #1927608: Remove the tight coupling between Block Plugins and Block Entities . Arguably at least there this should've been rectified, but that was at the height of the "we must get D8 done yesterday!" era, so it totally makes sense.)

    So this issue is definitely cleaning up some very old technical debt, that's caused confusion for every person who has ever looked at the exported YAML for blocks! 🚀

  • 🇫🇷France andypost

    Great find! Would be great to have CR for that change somehow as I bet some contrib already using the same pattern

  • Pipeline finished with Failed
    about 1 year ago
    Total: 616s
    #112902
  • Pipeline finished with Failed
    about 1 year ago
    Total: 491s
    #112930
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    #6: this will absolutely need a change record — probably multiple!

    Wow, with #5 fixed, plus one small fix to the ExtensionExists constraint, we went from 788 failures to 115 failures! Suddenly this became doable 😄

  • Pipeline finished with Failed
    about 1 year ago
    Total: 603s
    #112942
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Yay, and after refining the constraints for the sole block (the search block) whose settings I've added validation constraints to: 115 → 56 failures.

  • Pipeline finished with Canceled
    about 1 year ago
    Total: 190s
    #112949
  • Pipeline finished with Failed
    about 1 year ago
    Total: 530s
    #112953
  • Pipeline finished with Failed
    about 1 year ago
    #112972
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Reduced scope by:

    1. Undeprecating the (unused and useless) provider exported property in Block config entities around dropped us to 52 failures
    2. Undeprecating the status and info settings for "content block" blocks dropped us to 51 failures
  • Pipeline finished with Failed
    about 1 year ago
    Total: 504s
    #113007
  • Pipeline finished with Failed
    about 1 year ago
    Total: 492s
    #113042
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Rewrote issue summary 👍

  • Pipeline finished with Failed
    about 1 year ago
    Total: 482s
    #113066
  • Pipeline finished with Failed
    about 1 year ago
    Total: 202s
    #113103
  • Pipeline finished with Failed
    about 1 year ago
    Total: 604s
    #113112
  • Pipeline finished with Success
    about 1 year ago
    Total: 572s
    #113167
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    GREEN!

    Update path tomorrow.

    Very satisfied that I got this to green with just 18 files, +138, -49 in less than a day 🥳🚀 With this in, we could seriously accelerate config validation adoption, and Recipes indirectly!

  • Pipeline finished with Failed
    about 1 year ago
    Total: 559s
    #113542
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    2 of the 3 follow-ups created.

    Update path test pushed.

  • Pipeline finished with Failed
    about 1 year ago
    Total: 491s
    #113565
  • Pipeline finished with Success
    about 1 year ago
    Total: 567s
    #113610
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Update path pushed.

    3rd follow-up created (with MR!).

    Two blockers created:

    … both with a ready-to-review MR that's green. 😊

    Ready for final review! But please help land the two (trivial!) blockers first 😄

  • Status changed to Needs work about 1 year ago
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Status changed to Needs review about 1 year ago
  • Pipeline finished with Failed
    about 1 year ago
    Total: 579s
    #114423
  • Assigned to wim leers
  • Status changed to Needs work about 1 year ago
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    I found one tiny nitpick.

  • Pipeline finished with Success
    about 1 year ago
    Total: 491s
    #115005
  • Issue was unassigned.
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I started added explicit validation logic for all of the properties on Block config entities. I just pushed the test coverage for theme.

    But then I noticed that block.block.*:region doesn't have a validation constraint just yet! So this definitely needs more work before it is ready for final review. Will continue this next week.

  • Pipeline finished with Success
    about 1 year ago
    Total: 499s
    #115023
  • First commit to issue fork.
  • Pipeline finished with Success
    about 1 year ago
    Total: 601s
    #140766
  • Pipeline finished with Canceled
    about 1 year ago
    Total: 302s
    #143046
  • Pipeline finished with Failed
    about 1 year ago
    Total: 641s
    #143056
  • Pipeline finished with Failed
    about 1 year ago
    Total: 613s
    #160686
  • Pipeline finished with Failed
    about 1 year ago
    Total: 4446s
    #162198
  • Pipeline finished with Failed
    about 1 year ago
    Total: 491s
    #162441
  • Pipeline finished with Success
    about 1 year ago
    Total: 504s
    #162505
  • Pipeline finished with Success
    about 1 year ago
    Total: 572s
    #162523
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India narendraR Jaipur, India

    Marked NR for initial review.

  • Pipeline finished with Success
    about 1 year ago
    Total: 518s
    #163087
  • Status changed to Needs work 11 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    This is looking good but still needs some changes...

  • Pipeline finished with Success
    11 months ago
    Total: 617s
    #191718
  • Pipeline finished with Canceled
    11 months ago
    Total: 67s
    #192777
  • Pipeline finished with Failed
    11 months ago
    Total: 515s
    #192780
  • Pipeline finished with Success
    11 months ago
    Total: 551s
    #201921
  • Status changed to Needs review 11 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs work 11 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    A few questions but overall I think this looks pretty good.

  • Pipeline finished with Failed
    11 months ago
    Total: 596s
    #202677
  • Pipeline finished with Success
    11 months ago
    Total: 566s
    #202764
  • Pipeline finished with Success
    10 months ago
    Total: 510s
    #208440
  • Status changed to Needs review 10 months ago
  • 🇮🇳India narendraR Jaipur, India
  • Status changed to Needs work 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    Two very minor things (basically just rewordings), otherwise I think this is OK.

  • Pipeline finished with Failed
    10 months ago
    Total: 508s
    #213111
  • Pipeline finished with Success
    10 months ago
    Total: 609s
    #213553
  • Status changed to Needs review 10 months ago
  • 🇮🇳India narendraR Jaipur, India

    Feedback addressed

  • Status changed to RTBC 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    No objections here.

  • Status changed to Needs work 10 months ago
  • 🇳🇿New Zealand quietone

    I read the issue summary, the comments and the MR (not a code review). The find in #5 is great!

    I resolved the low hanging comments, leaving 7 to look at. I did find one unanswered question in the MR, I have the same question, so let's get that answered. Setting to NW.

    I think it would help if the issue summary explained why BlockInvalidRegionTest, testRebuildInvalidBlocks() are deleted

    I also question the need to shout at the reader in comments. I am referring to the use of 'TRICKY', a word that also have negative connotations. If we need to draw people's attention to something there is always the use of "Note that ...". There may be other options. This is not meant to block progress on this issue. This conversation may be more suitable for a separate issue.

  • 🇳🇿New Zealand quietone

    Forgot to add, that all the followup are made, with complete issue summaries and the links in the MR are correct.

  • Pipeline finished with Failed
    10 months ago
    Total: 165s
    #224397
  • Pipeline finished with Failed
    10 months ago
    Total: 173s
    #224418
  • Pipeline finished with Success
    10 months ago
    Total: 3425s
    #224473
  • Pipeline finished with Success
    10 months ago
    Total: 478s
    #227908
  • Pipeline finished with Success
    10 months ago
    Total: 477s
    #227916
  • Status changed to RTBC 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    I removed the unnecessary test coverage, but as far as I can tell, this is otherwise good to go. I'm going to go ahead and boldly restore RTBC here, and if there's anything further to fix, let's get it over the line. This issue is even more imperative since Create flexible config actions to place a block in the admin or default themes Needs review is close to ready.

  • Status changed to Needs work 10 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    I don't think that config validation issues shoudl just in a type widening for used values. Weight is always an integer once a block has been saved because config casts the value.

  • Pipeline finished with Failed
    10 months ago
    Total: 160s
    #228163
  • Pipeline finished with Failed
    10 months ago
    Total: 173s
    #228165
  • Pipeline finished with Failed
    10 months ago
    #228175
  • Status changed to Needs review 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    Alright, all done here AFAIK. I did the deprecation dance around non-integer block weights.

  • Pipeline finished with Failed
    10 months ago
    Total: 159s
    #228176
  • Status changed to Needs work 10 months ago
  • The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    10 months ago
    Total: 155s
    #228239
  • Pipeline finished with Failed
    10 months ago
    #228244
  • Pipeline finished with Failed
    10 months ago
    Total: 767s
    #228265
  • Pipeline finished with Canceled
    10 months ago
    Total: 132s
    #228277
  • Pipeline finished with Failed
    10 months ago
    Total: 495s
    #228279
  • Pipeline finished with Success
    10 months ago
    Total: 460s
    #228292
  • Status changed to Needs review 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Pipeline finished with Success
    10 months ago
    Total: 463s
    #228302
  • Status changed to Needs work 10 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Added some more review comments. Nice work on fixing up the int-ness of weight @phenaproxima

  • Pipeline finished with Failed
    10 months ago
    Total: 521s
    #228798
  • Pipeline finished with Canceled
    10 months ago
    Total: 195s
    #228883
  • Pipeline finished with Success
    10 months ago
    Total: 494s
    #228888
  • Pipeline finished with Success
    10 months ago
    Total: 1101s
    #228907
  • Status changed to Needs review 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    I think I've addressed all of @alexpott's feedback.

  • Pipeline finished with Success
    10 months ago
    Total: 2175s
    #228925
  • Status changed to Needs work 10 months ago
  • 🇺🇸United States tim.plunkett Philadelphia

    Reviewed

  • Status changed to Needs review 10 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    Okay, I agree with you @tim.plunkett; did the deprecation dance around page_id and added a change record.

  • Pipeline finished with Canceled
    10 months ago
    Total: 447s
    #231312
  • Pipeline finished with Failed
    10 months ago
    Total: 476s
    #231319
  • Status changed to RTBC 10 months ago
  • 🇺🇸United States tim.plunkett Philadelphia

    Great work, all!

  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    I reviewed it again today as well, and the one remark I had was answered. RTBC++

  • Pipeline finished with Success
    10 months ago
    Total: 1125s
    #231325
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Committed 1c21864 and pushed to 11.x. Thanks!

    Given where we are at in the 11.0.0 release cycle we can't commit this to 11.0.0 and have to target 11.1.0 instead. I've updated the deprecation messages and tests on commit.

    diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php
    index 2effc409b7..68582e48f0 100644
    --- a/core/modules/block/src/Entity/Block.php
    +++ b/core/modules/block/src/Entity/Block.php
    @@ -349,7 +349,7 @@ public function preSave(EntityStorageInterface $storage) {
         parent::preSave($storage);
     
         if (!is_int($this->weight)) {
    -      @trigger_error('Saving a block with a non-integer weight is deprecated in drupal:11.0.0 and removed in drupal:12.0.0. See https://www.drupal.org/node/3462474', E_USER_DEPRECATED);
    +      @trigger_error('Saving a block with a non-integer weight is deprecated in drupal:11.1.0 and removed in drupal:12.0.0. See https://www.drupal.org/node/3462474', E_USER_DEPRECATED);
           $this->setWeight((int) $this->weight);
         }
     
    diff --git a/core/modules/block/tests/src/Kernel/BlockValidationTest.php b/core/modules/block/tests/src/Kernel/BlockValidationTest.php
    index 9a1a2412d6..2456e7fb57 100644
    --- a/core/modules/block/tests/src/Kernel/BlockValidationTest.php
    +++ b/core/modules/block/tests/src/Kernel/BlockValidationTest.php
    @@ -176,7 +176,7 @@ public function testWeightValidation(): void {
       public function testWeightCannotBeNull(): void {
         $this->entity->set('weight', NULL);
         $this->assertNull($this->entity->getWeight());
    -    $this->expectDeprecation('Saving a block with a non-integer weight is deprecated in drupal:11.0.0 and removed in drupal:12.0.0. See https://www.drupal.org/node/3462474');
    +    $this->expectDeprecation('Saving a block with a non-integer weight is deprecated in drupal:11.1.0 and removed in drupal:12.0.0. See https://www.drupal.org/node/3462474');
         $this->entity->save();
       }
     
    diff --git a/core/modules/search/search.module b/core/modules/search/search.module
    index 8d5b1e330d..0944c53dcf 100644
    --- a/core/modules/search/search.module
    +++ b/core/modules/search/search.module
    @@ -428,7 +428,7 @@ function search_block_presave(BlockInterface $block) {
       if ($block->getPluginId() === 'search_form_block') {
         $settings = $block->get('settings');
         if ($settings['page_id'] === '') {
    -      @trigger_error('Saving a search block with an empty page ID is deprecated in drupal:11.0.0 and removed in drupal:12.0.0. To use the default search page, use NULL. See https://www.drupal.org/node/3463132', E_USER_DEPRECATED);
    +      @trigger_error('Saving a search block with an empty page ID is deprecated in drupal:11.1.0 and removed in drupal:12.0.0. To use the default search page, use NULL. See https://www.drupal.org/node/3463132', E_USER_DEPRECATED);
           $settings['page_id'] = NULL;
           $block->set('settings', $settings);
         }
    
  • Status changed to Fixed 10 months ago
    • alexpott committed 1c218641 on 11.x
      Issue #3379725 by Wim Leers, phenaproxima, narendraR, alexpott, quietone...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
Production build 0.71.5 2024