Problem/Motivation

#3379725: Make Block config entities fully validatable made Block config entities fully validatable, and the settings for 2 block plugins:

  1. content blocks (block.settings.block_content:*:) (see block_content.schema.yml
  2. the search form block block.settings.search_form_block (see search.schema.yml)

Steps to reproduce

N/A

Proposed resolution

Also make

views_block:
  type: block_settings
  label: 'View block'
  mapping:
    views_label:
      type: label
      label: 'Title'
    items_per_page:
      type: string
      label: 'Items per block'

block.settings.views_block:*:
  type: views_block

fully validatable.

Confusingly:

  • views_label is made available by \Drupal\views\Plugin\Block\ViewsBlockBase::buildConfigurationForm()
  • items_per_page is made available by \Drupal\views\Plugin\views\display\Block::blockForm()

The two are brought together into a single form by a third method: \Drupal\views\Plugin\Block\ViewsBlock::blockForm()

So … this seems surprisingly simple? 😄 All the actual control over the block lives in the associated View entity, not in the Views Block's configuration! Lucky us: no need for an update path! 😄

One complication:

        case 'items_per_page':
          $form['override']['items_per_page'] = [
            '#type' => 'select',
            '#title' => $this->t('Items per block'),
            '#options' => [
              'none' => $this->t('@count (default setting)', ['@count' => $this->getPlugin('pager')->getItemsPerPage()]),
              1 => 1,
              2 => 2,
              3 => 3,
              4 => 4,
              5 => 5,
              6 => 6,
              10 => 10,
              12 => 12,
              20 => 20,
              24 => 24,
              40 => 40,
              48 => 48,
            ],
            '#default_value' => $block_configuration['items_per_page'],
          ];

… which is why it's stored as type: string: it's either none, OR an integer >=1. We should change that to something more sensible:

type: integer
# In case you want to inherit the default
nullable: true
constraints:
  Range:
    min: 1

Remaining tasks

  1. Add the missing config schema.
  2. Review.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

TBD

Release notes snippet

TBD

Issue fork drupal-3520946

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

wim leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes
Status: Active » Needs work
Issue tags: +Needs update path, +Needs update path tests

I spoke slightly too soon 😅

borisson_’s picture

The update path should be moving none to null?

quietone’s picture

Version: 11.1.x-dev » 11.x-dev

phenaproxima made their first commit to this issue’s fork.

phenaproxima’s picture

Issue tags: -Needs update path

Update path is written, but still needs a test.

phenaproxima’s picture

Title: Make View blocks (block.settings.view_block:*) fully validatable » [PP-1] Make View blocks (block.settings.view_block:*) fully validatable
Status: Needs work » Postponed

Blocking this on #3520944: Make menu blocks (block.settings.system_menu_block:*) fully validatable, which makes a change to the BlockSettings migration plugin that will benefit this issue. (The change is complicated enough that it requires several tests to be adjusted, so I'd rather postpone than cross-port.)

bbrala’s picture

Just want to note; we do have AtLeastOneOfValidator nowadays, although cleaning up is good, just want to. mention it.

phenaproxima’s picture

Assigned: Unassigned » phenaproxima

#3520944: Make menu blocks (block.settings.system_menu_block:*) fully validatable is RTBC and unlikely to need any further changes before commit, so I'll proceed with this issue and base it in what's in there.

phenaproxima’s picture

Assigned: phenaproxima » Unassigned
Status: Postponed » Needs review
Issue tags: -Needs update path tests

Update path test written! This should still probably be committed after #3520944: Make menu blocks (block.settings.system_menu_block:*) fully validatable, but it's reviewable now.

longwave’s picture

Status: Needs review » Needs work

Same question as for the other issue about the update hook, plus some other questions.

longwave’s picture

Issue tags: +Needs change record

This also needs a change record as someone somewhere might be relying on that "none" string.

phenaproxima’s picture

Issue tags: -Needs change record
phenaproxima’s picture

Status: Needs work » Needs review
bbrala’s picture

Status: Needs review » Needs work

Looking good, left some small comments.

longwave’s picture

Title: [PP-1] Make View blocks (block.settings.view_block:*) fully validatable » Make View blocks (block.settings.view_block:*) fully validatable
phenaproxima’s picture

Status: Needs work » Needs review

Merged in changes from 11.x.

phenaproxima’s picture

Status: Needs review » Needs work

Damn it, I just realized that this update path is more complex than previously thought because Views blocks might be embedded in Layout Builder displays. (Same thing goes for #3520944: Make menu blocks (block.settings.system_menu_block:*) fully validatable but I guess that can be handled in a follow-up during beta.)

phenaproxima’s picture

Status: Needs work » Needs review
catch’s picture

#19: the Layout Builder concern is a known critical core bug

It's a known bug now as of a couple of weeks ago, but it's only become known because there are lots of proposed updates to block settings in the queue, which previously there weren't. I don't think that we had many block plugin settings updates in the past so we got away with it, as far as we know anyway.

If we fix the bug in layout builder (and it's also a bug in experience builder, and the navigation module), and have already added these block module-specific update paths to core, we will need to go through all of those updates paths and refactor them to the new system, if that's possible. So I'm not really sure what to do here.

catch’s picture

Probably the main question with #22 is whether this actually causes a problem or not for LB, if it doesn't, then it's not making things worse, but that probably needs manual testing at least.

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Needs review » Needs work
Issue tags: +Needs tests

I don't think that we had many block plugin settings updates in the past so we got away with it, as far as we know anyway.

True. But that doesn't make it less of a bug/oversight? 😅

The change I proposed and which @phenaproxima implemented means we can actually revert most update path logic.

I just also pushed a commit that removes the need for the items_per_page setting to exist on all views blocks, which further reduces the amount of change.

But I agree with @catch's concerns in #23, and I disagree with @phenaproxima's the fact that the tests don't break over this would seem to confirm it. — Views simply doesn't have sufficiently thorough tests to catch it. Plus … the logic was still checking for 'none' 😅.

So: this IMHO needs additional test coverage anyway, and if we're doing that, we might as well prove that #23 still continues to work.

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests

Missing test coverage added in https://git.drupalcode.org/project/drupal/-/merge_requests/11932/diffs?c....

That >fails tests, which shows @catch's concerns in #23 were justified: this would have broken views block instances in Layout Builder! 😨

Fixed in https://git.drupalcode.org/project/drupal/-/merge_requests/11932/diffs?c....

I think this is now ready for final review.

longwave’s picture

Status: Needs review » Needs work

Added a question about historical string values.

longwave’s picture

Status: Needs work » Reviewed & tested by the community

It's somewhat disappointing how difficult these seemingly simple config schema changes are to actually carry out, but I think this one is solid now, and the BC patterns and test coverage we figured out here can hopefully be reused in similar future issues.

wim leers’s picture

It's somewhat disappointing how difficult these seemingly simple config schema changes are to actually carry out

Isn't that more the strong reliance on typecasting and absence of validation in Views? (At least in this particular case.)

Either way: yay, and thanks so much!

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

I think we need a hook_block_presave here to handle triggering notifications for out of date exported default config.
We added one in \Drupal\search\Hook\SearchHooks::blockPresave for #3379725: Make Block config entities fully validatable so I think we should do the same here.

phenaproxima’s picture

Status: Needs work » Needs review

Added the presave hook and wrote a test. 🚀

penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed this, only a small nit (with a suggestion) which can be ignored at discretion of committers.

As I was only partially aware of the issue and didn't participate before, I read:

I didn't manually test this, but test coverage covers everything I could think of, and others have done before.

Honestly surprised and amazed of having more config schema validation for views!

Happy to see metrics up, one less to go! https://git.drupalcode.org/issue/drupal-3379725/-/jobs/2197356

  • larowlan committed 93d95f49 on 11.x
    Issue #3520946 by phenaproxima, wim leers, longwave, penyaskito,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 11.x - thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.