Problem/Motivation

The block add route can be accessed without the theme parameter. The theme select will appear at that point. Whenever the theme is changed, an AJAX callback will update the available regions. If a region is picked and then the theme is changed, a validation error will appear if the previously selected region doesn't exists for the new theme.
This is caused by the region list being updated inside the AJAX callback. This also causes the to lose the empty option added in the select element process.
Furthermore, due to this approach, the region list is not alterable during hook_form_alter() implementations.
For example, the block_region_permissions module cannot access the rebuilt list.

Steps to reproduce

How to reproduce the validation error:

  1. Login as a user with the administer blocks permission and visit admin/structure/block/add/system_powered_by_block (any other block will be fine);
  2. Select the Seven theme, then select the "Pre-content" region;
  3. Select back the Bartik theme. The error will be shown. Also notice the missing empty option.

Proposed resolution

Build the correct region list in the form, and just return the form element in the AJAX callback.

Remaining tasks

Finalise the test coverage.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

TBD.

Comments

sardara created an issue. See original summary.

sardara’s picture

Assigned: sardara » Unassigned
Status: Active » Needs review
StatusFileSize
new1.78 KB
new2.85 KB

Uploading a test and the fix. The test is just a start, I think we should add also the check that the options are the expected ones.

The last submitted patch, 2: 3173159-2-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sardara’s picture

StatusFileSize
new2.85 KB
new320 bytes

The coding standard fix.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
jeroent’s picture

StatusFileSize
new2.85 KB
new583 bytes

Tests were no longer running because of some coding standard issues.

jeroent’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative, +ddd2022

Code looks good to me, the code fixes this issue and has test coverage. So updating the status to RTBC.

Let's see if the testbot agrees.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 8ecb3da5dd to 10.0.x and 70d94d4972 to 9.4.x and 19c559c8d5 to 9.3.x. Thanks!

  • alexpott committed 8ecb3da on 10.0.x
    Issue #3173159 by sardara, JeroenT: Block add form ajax callback...

  • alexpott committed 70d94d4 on 9.4.x
    Issue #3173159 by sardara, JeroenT: Block add form ajax callback...

  • alexpott committed 19c559c on 9.3.x
    Issue #3173159 by sardara, JeroenT: Block add form ajax callback...

Status: Fixed » Closed (fixed)

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