Third party should be allowed to alter the section render array

Created on 19 June 2019, over 5 years ago
Updated 26 July 2024, 4 months ago

Problem/Motivation

In #2942661: Sections should have third-party settings , Section objects were given third-party settings so that contrib could put some data on Sections, presumably to modify how they work.

However, if a contrib module wanted to change how the section was rendered (for example, modifying the regions before they were passed to the layout, ala region styles), it wouldn't be able because there is no event or alter hook in Section::toRenderArray() in order to do so.

Also, it would make sense to have such an event, because in #2937799: Allow greater flexibility within SectionComponent::toRenderArray() a similar event is being called in SectionComponent::toRenderArray().

There's also another aspect which cannot be resolved without the ability of 3rd-party to hook-into the section render array building:

  • Block module’s scope is to place blocks.
  • Layout Builder module’s scope is to place blocks.

Block placements are decentralised. Each block placement is an config entity. Many modules can work together to place blocks on the same page. In other words a module providing a block placement, shouldn’t know if a different module provides also a placement on the same page or even on the same region.

Layout Builder placements are centralized. All the block placements are living in a single object (e.g. as 3rd-party settings of the entity view display). This means that the underlying object should know that the modules providing the block exists. As an effect, the object providing the block placements has hard dependencies on modules providing the blocks. Third-parties are not able to hook-in by themselves, they should be dependencies of the module that provides the object providing the placements.

Illustrating the issue

A landing page, assembling blocks, built with Layout Builder & Page Manager. Each block is provided by different modules, which are reusable units. This means that some projects might want not to use one or more of the modules that are providing the blocks. This not possible right now as the landing page config will have hard dependencies on the modules providing the blocks. This is possible with the Block module as each module is able to ship their block placements.

Proposed resolution

Call an event in Section::toRenderArray() allowing contrib modules to modify the $regions array before it's passed to $layout->build().

Remaining tasks

None.

User interface changes

None.

API changes

A new event - details to be determined.

Data model changes

None.

Release notes snippet

Todo.

Feature request
Status

Needs work

Version

11.0 🔥

Component
Layout builder 

Last updated 2 days ago

Created by

🇺🇸United States dsnopek USA

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    + @trigger_error('Calling LayoutBuilderContextTrait::getPopulatedContexts() without the $delta argument is deprecated in drupal:9.3.0 and the $delta argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3210520', E_USER_DEPRECATED);
    1. This will have to be updated for 10.1 and 11

    Not needed but would be useful to have a tests-only.patch

  • Merge request !5866rebase for 11.x → (Open) created by heddn
  • heddn Nicaragua

    I've rebased and pushed to issue/3062862-layout-3rd. Still need to reply to #61.

  • 🇨🇿Czech Republic milos.kroulik

    It looks like it doesn't work without specifying event name for SectionBuildRenderArrayEvent (at least in Drupal 10.2), such as

      const SECTION_BUILD_RENDER_ARRAY = 'section.build.render_array';
    

    I will update the MR shortly based on this.

  • 🇳🇮Nicaragua edysmp Nicaragua

    #64: Event names are not required. You can use the event's class name when subscribing.
    e.g

    $events[SectionBuildRenderArrayEvent::class] = ['onSectionBuildRender'];
    
Production build 0.71.5 2024