Problem/Motivation

Layout Builder currently provides all field blocks, and all blocks, as placeable items via the Settings Tray. On most sites, content builders will not want to place most of the Drupal-provided meta fields, and on many sites, a curated list of placeable blocks would be preferable. Illustration, using the "Article" node type:

Current UI:
UI of Settings Tray

Desired (configurable) UI:
UI of Settings Tray

Proposed resolution

Developers should use the new hooks provide in New hooks available for filtering plugins at runtime to alter the list of blocks.

Previous options

While the "right" way to curate this list might be permissions-based, Drupal 8 core does not have per-block-type permissions, nor does it have per-field-type permissions.

1. The recommended solution for developers could be to use an event subscriber to extend the base Drupal\layout_builder\Controller\ChooseBlockController to fit their site's needs. If this is the case, we should create documentation of how to do this.

2. Another option would be to add a hook that allows modules to manipulate the list of blocks created by Drupal\layout_builder\Controller\ChooseBlockController

3. Alternatively, Layout Builder's implementation of the "Manage Display" form for each entity type could provide a selectable list of what fields should be allowed to be placed via the Layout UI, and a similar admin UI could be provided for curating which block types should be placeable.

Remaining tasks

- Determine recommended resolution (see above)
- Implement recommended resolution

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mark_fullmer created an issue. See original summary.

mark_fullmer’s picture

Issue summary: View changes
mark_fullmer’s picture

Version: 8.6.x-dev » 8.5.x-dev
Issue summary: View changes
mark_fullmer’s picture

The attached patch provides a new hook to Layout Builder which allows modules to adjust the list of blocks that will be available in the settings tray.

Manual testing would involve copying the example hook from layout_builder.api.php and verifying that the 'Help' block is removed, along with Drupal-provided field_block elements.

tim.plunkett’s picture

Title: [Layout Builder] Provide ability to curate ChooseBlockController » Provide ability to alter blocks presented in ChooseBlockController
Version: 8.5.x-dev » 8.6.x-dev
Issue tags: +Blocks-Layouts
FileSize
3.94 KB
4.98 KB

Great suggestion!
I think it'd be a bit cleaner to do the filtering before blocks are grouped and processed, like this.
(interdiff is a bit messy, but it's there)

mark_fullmer’s picture

I fully agree that the hook should happen before the grouping/processing (since that part is really only doing formatting).

Testing of 2946227-layout_blocks-5.patch works as expected, & a double-check of coding standards all checks out.

This has my nominal RTBC! (I'll let the Layout Builder folks take it from there.)

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: +Needs tests

The Usability tag is misleading, but accurate. This does not improve usability at all; it allows other modules to improve the usability.
This hook would be key to building a UI to facilitate this sort of selecting/deselecting blocks.

I think it deserves some test coverage to prove that it actually affects the UI correctly.

mark_fullmer’s picture

Attached is a test to prove that the added API hook affects the UI.

Scope:
- Adds tests/modules/layout_builder_test, which implements hook_layout_builder_choose_blocks_alter().
- Adds LayoutBuilderAPITest, which enables layout_builder_test, and verifies that the UI is affected:
- "Sticky at top of lists" link is not present
- "Help" block is not present
- "Powered by Drupal" block is present
- "Default revision" is present

samuel.mortenson’s picture

Really happy to see this issue - we have a similar hook in Panels IPE, hook_panels_ipe_blocks_alter. Two thoughts:

1. I wonder if a similar hook for Layouts would also be helpful - a few themes and modules provide Layouts by default and there are usually a few duplicates. For example if I'm using Layout Builder and Bootstrap, I would only want to show Bootstrap's two-column Layout, not what core provides.

2. Should we make the Section Storage available to the hook implementers? It may be useful to have different blocks per Content Type, or if an Entity has a specific field value, for instance.

mark_fullmer’s picture

I wonder if a similar hook for Layouts would also be helpful - a few themes and modules provide Layouts by default and there are usually a few duplicates. For example if I'm using Layout Builder and Bootstrap, I would only want to show Bootstrap's two-column Layout, not what core provides.

+1 to this feature. This very thing is part of my team's acceptance criteria for being able to use Layout Builder as the layout solution in our distribution.

caspervoogt’s picture

Also +1 to samuel.mortenson's notion of a similar hook to hook_panels_ipe_blocks_alter for Layout Builder.

Pancho’s picture

tim.plunkett’s picture

bkosborne’s picture

+1 to this. Even if LB doesn't provide the UI, a contrib module could do it and it could eventually be merged into core.

swentel’s picture

I like the hook approach, because it's easier for a (base) theme or themers to implement this. It would for instance also allow themes to use theme settings to expose some configuration to alter the list of blocks.

mark_fullmer’s picture

Once https://www.drupal.org/project/drupal/issues/2949177 has been committed, we have the ability to pretty easily curate things in the Layout Builder UI. I've attached a proof-of-concept (which assumes https://www.drupal.org/files/issues/2018-04-17/2949177-plugin_filter-26.... is merged).

Conceptualization
1. Add a per entity-type + view mode -level third-party setting that lists all blocks available in the system & allows choosing which should be displayed.
2. Leverage the new plugin filter hook so that this list, itself, can be curated by sites as needed.
3. Only affect the listing of items in ChooseBlockController, so that if items are added to a layout, and the list is *subsequently* curated, the list is non-destructive to the existing layout.

Obviously, there are some big questions related to UI (the list of blocks could easily become enormous), and even whether this would better go in contrib, so I'd love to get feedback from the Layout Initiative folks, but am happy to continue working on this if it seems like the right direction.

Status: Needs review » Needs work

The last submitted patch, 16: 2946227-curate-layout-builder-blocks-16.patch, failed testing. View results

tim.plunkett’s picture

Took this and tried to see how hard it would be to do from contrib.
Turns out, it's doable with one straightforward addition: adding third party settings support to defaults section storage (which just passes it along to the config entity).

This also has tests now.

The -do-not-test patch is just the code for this issue, -combined contains #2949177: Introduce a service that returns filtered plugin definitions

tim.plunkett’s picture

#2962248: Layout Builder defaults should support third party settings contains the code needed to accomplish this from contrib.

Status: Needs review » Needs work

The last submitted patch, 18: 2946227-block-restriction-18-combined.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

zuernBernhard’s picture

So this one can be committed ?

tedbow’s picture

Issue summary: View changes

@zuernBernhard I think what @tim.plunkett's code in #18 proves is now that #2949177: Introduce a service that returns filtered plugin definitions has been committed it would be very easy to accomplish what this patch is trying to do in contrib module.

@see core/lib/Drupal/Core/Plugin/plugin.api.php and core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module function layout_builder_test_plugin_filter_block__layout_builder_alter

Also see the change record here: New hooks available for filtering plugins at runtime

It probably makes more sense to do this contrib. This was to Provide ability to alter blocks presented in ChooseBlockController which the new hooks do.

zuernBernhard’s picture

Ok, the new hooks are commited to 8.6. Right now in 8.5 i use the atteched "dirty hack patch" in the ChooseBlockController. Otherwise I can't see all the Blocks I need in /admin/structure/types/manage//display

Perhaps it would be nice to be able to configure the available contexts somethere or to expose them as "filter" to the user above the list of available blocks.

tedbow’s picture

Status: Needs work » Closed (duplicate)