Drupal 10.1 introduces naming change that affects content block restrictions

Created on 26 May 2023, over 1 year ago
Updated 7 July 2023, over 1 year ago

Problem/Motivation

As observed with tests Drupal 10.1.x, Drupal 10.1's change from labelling block content entities as "Custom blocks" to "Content blocks" affects the business logic in Layout Builder Restrictions. In particular, in previous versions, restrictions on block content entities were stored under a key of Custom blocks. A site updating to Drupal 10.1 with Layout Builder Restrictions on custom blocks would see those restrictions no longer applying, since Drupal would now be categorizing those blocks as Content block.

https://www.drupal.org/pift-ci-job/2677038

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇺🇸United States mmarler

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

Comments & Activities

  • Issue created by @mmarler
  • Issue was unassigned.
  • 🇺🇸United States mark_fullmer Tucson

    Looks like these failing tests are due to the name change in Drupal 10.1 from "Custom block" to "Content block." The attached patch is a partial fix, changing the naming on most of the test logic.

    However, there may be a remaining functional change that needs to be made, which is why some tests are still failing. Changing priority to "Major".

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    21 pass, 1 fail
  • 🇺🇸United States mark_fullmer Tucson

    Also: it appears that this will likely be B/C breaking for Drupal 10.0... , meaning, after this change, sites running < 10.1 can't update safely, so we'll need to create a new minor version release for 10.1+

  • 🇺🇸United States mark_fullmer Tucson
  • 🇺🇸United States mark_fullmer Tucson
  • 🇺🇸United States mark_fullmer Tucson

    The attached patch -- not for merging -- provides a demonstration of the naming changes needed to make this work with Drupal 10.1. However, it would not be backwards compatible with Drupal 9.x or 10.0.x. Therefore, we should explore whether we can "rewrite" the "Content block" label in a more targeted way to allow this to be compatible with prior versions.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    22 pass
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    22 pass
  • 🇺🇸United States mark_fullmer Tucson

    The attached patch provides an affordance to retain the existing "Custom blocks" labelling that was present prior to Drupal 10.1. This will allow sites running on Drupal 9.5.x, 10.0.x, or 10.1.x to use this.

    One consequence of this, however, is that the test logic will differ between Drupal 10.1 and Drupal 10.0, so we will not expect tests to pass anymore on Drupal 10.0 or lower.

    The second attached patch omits the changes to the test logic in order to demonstrate that the business logic change will still work with Drupal 10.0 or lower.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    24 pass
  • 🇳🇴Norway eiriksm Norway

    Would it not be possible to try to check both of these labels though? And then change the logic conditionally, and pass the tests conditionally? Disclaimer: I did not actually look through the patches, just my thought that it seems like it should be possible? And if not: why not?

  • 🇺🇸United States mark_fullmer Tucson

    Hi Eirik! I appreciate a co-maintainer weighing in on this. Yes, you're absolutely right that it is possible to check for both the labels "Custom blocks" and "Content block" and group them in the same restrictions category, thereby making a single release of this module compatible with 9.5.x / 10.0.x / 10.1.x.

    So, in effect, this is not a backwards-compatibility-breaking change as I suspected in a previous comment.

    That's where the patch in #8 ended up. What I'm not sure about is whether the test logic can also be done conditional on the Drupal version (or if it's even worth the effort to make it conditional). Thoughts on that?

    Thanks again!

  • 🇳🇴Norway eiriksm Norway

    I think that would be possible indeed. I see the patch is compatible indeed, but the test not.

    So something like

    $candidate_found = false;
    Foreach $label_candidates
    //Check for element
    If (!$candidate_found)
    Throw exception

    Sorry for the pseudo non usable code. On vacation and I am writing on my phone ✌️🤓

  • 🇺🇸United States mark_fullmer Tucson

    Foreach $label_candidates

    Yeah, I think that would work, but there are so many references in the test suite that I think a change like that would make the test code significantly more difficult to maintain. I was picturing a helper method in the test suite that checked the Drupal core version and switched the expectations. Something like

    Before:

        $element = $page->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-custom-blocks-restriction-all"]');
        $assert_session->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-custom-blocks-restriction-all');
        $assert_session->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-custom-blocks-restriction-allowlisted');
        $element = $page->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-custom-blocks-restriction-allowlisted"]');
    

    After:

        $element = $page->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-' . $block_target . '-restriction-all"]');
        $assert_session->checkboxChecked('edit-layout-builder-restrictions-allowed-blocks-' . $block_target . '-restriction-all');
        $assert_session->checkboxNotChecked('edit-layout-builder-restrictions-allowed-blocks-' . $block_target . '-restriction-allowlisted');
        $element = $page->find('xpath', '//*[@id="edit-layout-builder-restrictions-allowed-blocks-' . $block_target . '-restriction-allowlisted"]');
    

    Given Drupal 9's EOL in November, I'm just not sure if it's worth the effort...

  • 🇳🇴Norway eiriksm Norway

    That's a good point. Priority one would have to be to actually support this is both versions which the patch already does. But maybe we can open an issue about running the tests on d9 at least? I will do that and link it here

    Otherwise looked through the patch which makes sense and maintain backwards compatibility ✌️

    • mark_fullmer committed f699906a on 8.x-2.x
      Issue #3363076 by mark_fullmer, eiriksm, mmarler: Drupal 10.1 introduces...
  • Status changed to Fixed over 1 year ago
  • 🇺🇸United States mark_fullmer Tucson

    Agreed that we should make this change and follow-up with test compatibility for < 10.1.

    Thanks, Eirik, and have a good rest of the vacation!

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

Production build 0.71.5 2024