After setting "Allow specific blocks" for a category, newly created blocks are not allowed

Created on 20 December 2023, 12 months ago
Updated 16 May 2024, 7 months ago

Trying to add more blocks from manage display during second save won't get displayed in the layout builder.

Steps to reproduce

  1. Go to Content types> any content type > Enable Layout
  2. Select some content fields and save.
  3. In the manage layout, you'll be able to find the selected fields in layout builder.
  4. Now, if new content fields are added in manage display and saved, these won't be displayed in layout builder
🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇮🇳India Yashaswi18

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

Comments & Activities

  • Issue created by @Yashaswi18
  • Status changed to Postponed: needs info 12 months ago
  • 🇺🇸United States mark_fullmer Tucson

    Thanks for posting this issue about the module usage. From what I'm hearing, you are describing the intended behavior of one of the restriction options for Layout Builder Restrictions: if you use the "Allow specific [block type] blocks" restriction, the blocks available for placement will be limited to the ones selected, and blocks added in configuration after that will not be allowed.

    There are two ways that you can achieve your goal:

    1. When new blocks are added to a category, update the restrictions to allow the new block(s) that you want to allow. This requires manual configuration updating. However, since on most sites, the people who add fields/blocks are also the people who configure the Layout Builder Restrictions, this is usually sufficient: it just needs to be part of the site building process. Indeed, I think that most sites require manual configuration maintenance for these restrictions when new fields/blocks become available, because in most cases, some new blocks should be allowed and some should not: someone needs to set which ones are which.

    2. Use the "Restrict specific [block type] blocks" setting, and select only the block(s) that you do not want people to use. New blocks will then automatically be allowed. For more explanation on this setting, see https://www.drupal.org/docs/contributed-modules/layout-builder-restricti...

    If I am misinterpreting the original question, please clarify!

  • 🇮🇳India Yashaswi18

    What is actually happening is that when some content fields are selected from the list for the first time and saved, it'll be displayed in the layout builder, again when we need some more content fields to be displayed in the layout builder, we go to the Manage display> under Allow specific content fields> We select few more content fields (already existing ones) from the list and save it. Now, in the manage layout, we won't be able to find the content fields that we have added again in the second time.

  • 🇺🇸United States mark_fullmer Tucson

    Thank you for the additional explanation. I was misinterpreting the original report. With my new understanding(!), I tried to reproduce the problem described and was unable to do so. Here are the steps I took:

    1. With Layout Builder Restrictions installed, enable Layout Builder on the "Basic Page" content type's "default" display (/admin/structure/types/manage/page/display).
    2. In "Blocks available for placement" > "Content fields" > Allow specific Content fields blocks", select only "Body" and save.
    3. Create a new "page" node (/node/add/page)
    4. Click the "Layout" tab, then "Add block" in a region. Observe that only "Body" is available as a selectable field.
    5. Add a new field to the Page type (admin/structure/types/manage/page/fields) called "Test".
    6. On the previously created node, click the "Layout" tab, then "Add block" in a region. Observe that only "Body" is available as a selectable field (expected, based on restrictions).
    7. On the Page type's Manage Display tab (admin/structure/types/manage/page/display), allow "Test" as a selectable field and save.
    8. On the previously created node, click the "Layout" tab, then "Add block" in a region. Observe that "Body" and "Test" are available.

    If you can clarify whether or not you are able to reproduce the problem with these steps, and/or provide other steps to reproduce the problem you are experiencing, that would be wonderfully helpful. I'll leave this in "Maintainer needs more info" status until then.

  • 🇮🇳India Yashaswi18

    It works as expected when we do it for the particular content that has been created, the layout builder shows the newly added content fields (node/id/layout). But, when you click on "Manage Layout" from Manage Display page, and check in the layout builder here, the content fields are not appearing in the layout builder list (admin/structure/types/manage/content_type/display/default/layout).

  • 🇺🇸United States mark_fullmer Tucson

    But, when you click on "Manage Layout" from Manage Display page, and check in the layout builder here, the content fields are not appearing in the layout builder

    Thanks for the additional clarification. Unfortunately, I'm unable to reproduce the problem. Here are the steps I took:

    1. With Layout Builder Restrictions installed, enable Layout Builder on the "Basic Page" content type's "default" display (/admin/structure/types/manage/page/display).
    2. In "Blocks available for placement" > "Content fields" > Allow specific Content fields blocks", select only "Body" and save.
    3. Create a new "page" node (/node/add/page)
    4. Click the "Layout" tab, then "Add block" in a region. Observe that only "Body" is available as a selectable field.
    5. Add a new field to the Page type (admin/structure/types/manage/page/fields) called "Test".
    6. On the previously created node, click the "Layout" tab, then "Add block" in a region. Observe that only "Body" is available as a selectable field (expected, based on restrictions).
    7. On the Page type's Manage Display tab (admin/structure/types/manage/page/display), allow "Test" as a selectable field and save.
    8. On the Page type's Manage Display, click the "Manage layout," then "Add block" in a region. Observe that "Body" and "Test" are available.
  • 🇮🇳India Yashaswi18

    In the screenshot I've attached, you will be able to see that I haven't enabled "Allow each content item to have its layout customized" option. It works fine when checked in the node's layout builder tab.
    I'm trying to add a new content field through the manage layout option of that particular content type from the manage display (Content type> any content type> Manage Display> Enable layout builder> Select some content fields under allow specific content fields > Save> Click on Manage layout > Add Block). We will find the selected content fields.
    But now again after the first save, if I select some more content fields and save, newly added content fields are not appearing in the layout builder (admin/structure/types/manage/content_type/display/default/layout) when I try to add the block.
    Even if I select the "Restrict specific content fields" and select some content fields, it still shows the content fields that were added during the first save in the layout builder.

    Version : 8x-2.19
    Drupal Version : 9.5.11

  • Status changed to Active 12 months ago
  • 🇺🇸United States mark_fullmer Tucson

    you will be able to see that I haven't enabled "Allow each content item to have its layout customized" option

    Thanks. In my testing, this is not a factor in the issue. I *was* finally able to reproduce the problem, and can explain a simple fix you can do to resolve the issue.

    The problem has to do with how Drupal saves an "interim" revision in its State API when you view the "Manage Display" tab. When you were viewing the "Manage Display" tab prior to adding the field, Drupal saved this temporary revision to the layout, even though you didn't make any changes to the layout. This Drupal core behavior is explained in https://www.drupal.org/project/drupal/issues/3204494#comment-14235288 🐛 Content Not reverting in Layout builder section Active

    As a result, apparently, the available fields are also stored in the state.

    As an immediate workaround, when you first navigate to the "Manage Display" tab to update which fields are available in the default layout, first click "Discard changes." You won't lose your previous settings; it will just clear out this in-progress revision mentioned above. After this, you should see the new field(s) available for placement.

    If I have time, I'll look into whether there's a way that Layout Builder Restrictions can help avoid this scenario, for example, by getting the list of available fields fresh, rather than from the current revision.

  • 🇮🇳India Yashaswi18

    Thank you for providing the workaround, it worked when I clicked on "Discard Changes" first and then open the manage layout page again.
    Getting the list of available fields fresh, rather than the current revision would also be helpful. :)

  • 🇺🇸United States mark_fullmer Tucson
Production build 0.71.5 2024