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

Review use of Drupal\Core\Cache\CacheableMetadata, see https://git.drupalcode.org/project/drupal/-/merge_requests/5866#note_814639
Review change record

User interface changes

None.

API changes

A new event - details to be determined.

Data model changes

None.

Release notes snippet

Todo.

Issue fork drupal-3062862

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dsnopek created an issue. See original summary.

dsnopek’s picture

Status: Active » Needs work
StatusFileSize
new7.92 KB

Here's a patch to demonstrate what this could look like. I haven't actually tested this (manually or automatically), and I'd like to actually experiment with implementing region styles and other possible use-cases before really committing to and finishing the implementation.

One thing that changed once digging into this patch, is that I realized that the event that's (most likely) needed for region styles wouldn't operation on the render array, but the regions array before it's passed to the layout, which isn't technically a render array. Per the docs on LayoutInterface::build() it's an array of render arrays keyed by region name, and specifically in the context of layout_builder Sections, it's actually an array of regions, where each region is an array of the render arrays for each of the components. This is important, because we need to know that that's what it is if we want to implement a region style that turns each component into a tab, or an item in an accordion, etc.

Also, that's the alter event that happens before we ask the layout to do it's thing, but I could some contrib module wanting an alter event on the render array AFTER the layout does it's thing, so the patch includes an event for that as well.

yogeshmpawar’s picture

Status: Needs work » Needs review

Changing status to Needs Review & Triggering bots.

Status: Needs review » Needs work

The last submitted patch, 2: drupal8-section-render-3062862-2.patch, failed testing. View results

dsnopek’s picture

Using the patch here, I've started experimenting with implementing region styles in this sandbox:

https://www.drupal.org/sandbox/dsnopek/3059795

It has a couple examples, including an "Accordion" style which puts all the blocks in the region into a jQuery UI accordion. Already, this points to a weakness in the current patch here, because it's difficult to get the block title and to hide it from normal rendering.

The thought I had immediately is that the LayoutBuilderEvents::SECTION_BUILD_REGIONS_ARRAY event shouldn't just get an array of the block's render arrays, but that layout_builder should register it's own event subscriber which builds that. Then my contrib module can register an event subscriber that comes before layout_builder's one, and do it's own rendering, which would allow the region style to easily grab the block label, and then also change the block settings to hide the label before generating the render array.

When I get a chance, I'll try that, and then post a new patch here if it works out well.

dsnopek’s picture

Status: Needs work » Needs review
StatusFileSize
new12.48 KB
new8.06 KB

Here's a new patch that makes the changes I discussed in #5:

  1. The event object takes the section components
  2. An event subscriber actually renders those components into the regions array (this makes this closer to what SectionComponents::toRenderArray() is doing too

This allowed my experimental implementation of region styles to deal with block titles easier, and made for a simpler and better accordion region style. (I'll be pushing my code to the sandbox for that in a couple minutes.)

This is probably ready for others to comment on, so setting status to "Needs review"

Status: Needs review » Needs work

The last submitted patch, 6: drupal8-section-render-3062862-5.patch, failed testing. View results

tim.plunkett’s picture

Issue tags: +Blocks-Layouts, +Needs tests
  1. +++ b/core/modules/layout_builder/src/Section.php
    @@ -81,14 +83,21 @@ public function __construct($layout_id, array $layout_settings = [], array $comp
    +    $event = new SectionBuildRegionsArrayEvent($this->getComponents(), $this, $contexts, $in_preview);
    +    $event_dispatcher->dispatch(LayoutBuilderEvents::SECTION_BUILD_REGIONS_ARRAY, $event);
    

    I'm not sure I understand the purpose of this event. Maybe it'd be clearer with a test implementation.

  2. +++ b/core/modules/layout_builder/src/EventSubscriber/SectionRegionsArray.php
    @@ -0,0 +1,44 @@
    +  public function onBuildRegions(SectionBuildRegionsArrayEvent $event) {
    +    $regions = $event->getRegions();
    +
    +    foreach ($event->getComponents() as $component) {
    +      if ($output = $component->toRenderArray($event->getContexts(), $event->inPreview())) {
    +        $regions[$component->getRegion()][$component->getUuid()] = $output;
    +      }
    +    }
    +
    
    +++ b/core/modules/layout_builder/src/Section.php
    @@ -81,14 +83,21 @@ public function __construct($layout_id, array $layout_settings = [], array $comp
    +    $build = $this->getLayout()->build($event->getRegions());
    ...
    +    $event = new SectionBuildRenderArrayEvent($build, $this, $contexts, $in_preview);
    +    $event_dispatcher->dispatch(LayoutBuilderEvents::SECTION_BUILD_RENDER_ARRAY, $event);
    

    Oh, this is backwards from what I expected. This code lives in the _region_ build event?

Why have two events at this point? Moving the core implementation to a subscriber itself allows someone to participate both before and after core. Couldn't a single event handle this?

dsnopek’s picture

StatusFileSize
new32.68 KB
new14.87 KB

@tim.plunkett: Thanks for taking a look!

I'm not sure I understand the purpose of this event. Maybe it'd be clearer with a test implementation.

I have an example implementation in this sandbox module:

https://git.drupalcode.org/sandbox/dsnopek-3059795/blob/8.x-2.x/src/Even...

It implements region styles. If you enable the 'block_style_plugins_ng_examples' module, it includes an accordion region style that makes each block in the region be an item in the accordion.

To actually test it, once you put some blocks in a region in layout_builder, a "Configure region style" link will appear at the top of the region:

Which looks like this when rendered:

Why have two events at this point? Moving the core implementation to a subscriber itself allows someone to participate both before and after core. Couldn't a single event handle this?

The 1st event operates on the regions array that is passed to the layout - this is used for my region styles implementation. The 2nd event operates on the render array that comes back from the layout. So, the layout is doing it's business between the two events.

I honestly don't currently have a use-case for the 2nd event. My thinking was just that some contrib might put something on the third-party settings of a Section, and want to use that to modify the fully finished render array (with the layout applied and everything). So, it was really added for "completeness" because without an event or hook after the layout does it's business, you wouldn't be able to alter the fully finished render array in a generic way (ie. regardless of how the Section is being used, be that to render an entity like core does, or to render a page_manager variant per #2960739: Create a layout builder variant).

tim.plunkett’s picture

If the second event also came with a setRegions() method, your example code set an earlier priority than core and manipulate the event payload there.

That might be attempting to streamline it too much, idk

dsnopek’s picture

I don't know if exactly that would work. Currently, the patch has got these things happening in this order:

  1. Event nr 1: layout_builder and/or contrib collaborate to produce the $regions array
  2. $build = $layout->build($regions)
  3. Event nr 2: contrib can modify the $build render array

So, like, setting the $regions array in event nr 2 doesn't matter, because the layout already took that, and converted it into the $build render array.

I suppose if layout_builder (or my module's) event subscriber on event nr 1 also did the $build = $layout->build($regions) part, then it'd be a matter of whether or not your event subscriber ran before or after it?

That seems like it'd make for convoluted DX, though, it'd be like, "set your priority higher than 100 to mess with the $regions array, and lower than 100 to mess with the $build array - if you mix that up, your changes will have no effect."

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nicxvan’s picture

I think I may be misunderstanding how this works or it is not working properly.

I've created an event subscriber called Section forms based on the example provided here: https://git.drupalcode.org/sandbox/dsnopek-3059795/-/blob/8.x-2.x/src/Ev...

My end goal is to take a value that is set on each section when it's been added and feed that value into a form so that each section has a form element button that I can use to perform `some` action.

My understanding based on this and the example is that I need a onBuildRegions event that I can then grab the section configuration then generate the form and output it.

Here is the simplified eventsubscriber I am working with, the log nor the exit ever get hit when visiting the page with the sections on it.

<?php

namespace Drupal\nicxvan_test_module\EventSubscriber;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\layout_builder\Event\SectionBuildRegionsArrayEvent;
use Drupal\layout_builder\LayoutBuilderEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Adds Layout Builder section styles.
 */
class SectionForms implements EventSubscriberInterface {

  /**
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerFactory;

  /**
   * Constructs SectionStyles.
   *
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
   */
  public function __construct(LoggerChannelFactoryInterface $logger_factory) {
    $this->loggerFactory = $logger_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [];

    // Skip this if the Layout Builder is not installed.
    if (class_exists('\Drupal\layout_builder\LayoutBuilderEvents')) {
      $events[LayoutBuilderEvents::SECTION_BUILD_REGIONS_ARRAY] = ['onBuildRegions', 1000];
    }

    return $events;
  }

  /**
   * Add styles to section regions.
   *
   * @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event
   *   The section component build render array event.
   */
  public function onBuildRegions(SectionBuildRegionsArrayEvent $event) {
    // Prevent layout_builders normal region building.

    $this->loggerFactory->get('nicxvan_test_module')->error('something wrong');

    $regions = $event->getRegions();
    $section = $event->getSection();
    $layout = $section->getLayout();

    kint($section);
    exit();

    $components = [];
    foreach ($event->getComponents() as $component) {
      $components[$component->getRegion()][$component->getUuid()] = $component;
    }

    foreach ($layout->getPluginDefinition()->getRegionNames() as $region) {
      if (empty($components[$region])) {
        continue;
      }

      // Or if no region style is configured, simply render each component.
      foreach ($components[$region] as $key => $component) {
        $regions[$region][$key] = $component->toRenderArray($event->getContexts(), $event->inPreview());
      }
    }

    $event->setRegions($regions);
  }

}
dsnopek’s picture

@nicxvan One quick thing to double check: are you registering the event subscriber in your module's MODULE.services.yml file? Probably you are, but throwing that out there, just in case.

Also, do you have my 'block_style_plugins_ng' module installed? If so, it could be that its event subscriber is running first, and the $event->stopPropagation() there is preventing yours from running. There can really only be one subscriber that takes over this event the way my sandbox module does (although, you could have some light weight subscribers that run before it and make some small modifications to the data or something).

For what you're trying to do, I wonder if instead of subscribing to this event, you could use my 'block_style_plugins_ng' module to make a regions style plugin? From a region style plugin you can modify each block, like the 'Accordion' region style does in the examples.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

erik seifert’s picture

Same problem here. I try to implement a pluggable system for region and section styles. But this is not possible at this time.

claudiu.cristea’s picture

claudiu.cristea’s picture

claudiu.cristea’s picture

@tim.plunkett,

I'm not sure I understand the purpose of this event. Maybe it'd be clearer with a test implementation.

I see the value. I described in deep the need, in the #3210230: Block placements by 3rd-party in layout section description. Will update also here the IS to clarify.

This certainly needs a change notice.

  1. +++ b/core/modules/layout_builder/layout_builder.services.yml
    @@ -40,6 +40,10 @@ services:
    +    class: Drupal\layout_builder\EventSubscriber\SectionRegionsArray
    
    +++ b/core/modules/layout_builder/src/EventSubscriber/SectionRegionsArray.php
    @@ -0,0 +1,44 @@
    +class SectionRegionsArray implements EventSubscriberInterface {
    

    Let's rename it to SectionRenderArraySubscriber

  2. +++ b/core/modules/layout_builder/src/Event/SectionBuildRegionsArrayEvent.php
    @@ -0,0 +1,128 @@
    + * @see \Drupal\layout_builder\LayoutBuilderEvents::SECTION_BUILD_REGIONS_ARRAY
    
    +++ b/core/modules/layout_builder/src/LayoutBuilderEvents.php
    @@ -26,4 +26,37 @@
    +  /**
    +   * Name of the event fired when a section's render array is built.
    +   *
    +   * This event allows modules to collaborate on creating the render array of
    +   * the Section object. The event listener method receives a
    +   * \Drupal\layout_builder\Event\SectionBuildRenderArrayEvent instance.
    +   *
    +   * @Event
    +   *
    +   * @see \Drupal\layout_builder\Event\SectionBuildRenderArrayEvent
    +   * @see \Drupal\layout_builder\Section::toRenderArray()
    +   *
    +   * @var string
    +   */
    +  const SECTION_BUILD_RENDER_ARRAY = 'section.build.render_array';
    

    Symfony event dispatcher component is dropping this constant and uses the event class full qualified name as event ID. Let's follow that path. Event constants may create issues, see also #2825358: Event class constants for event names can cause fatal errors when a module is installed

  3. +++ b/core/modules/layout_builder/src/Event/SectionBuildRegionsArrayEvent.php
    @@ -0,0 +1,128 @@
    +class SectionBuildRegionsArrayEvent extends Event {
    
    +++ b/core/modules/layout_builder/src/LayoutBuilderEvents.php
    @@ -26,4 +26,37 @@
    +  /**
    +   * Name of the event fired when a section's regions array is built.
    +   *
    +   * This event allows modules to collaborate on creating the regions array of
    +   * the Section object that will be passed to the layout. The event listener
    +   * method receives a \Drupal\layout_builder\Event\SectionBuildRenderArrayEvent
    +   * instance.
    +   *
    +   * @Event
    +   *
    +   * @see \Drupal\layout_builder\Event\SectionBuildRegionsArrayEvent
    +   * @see \Drupal\layout_builder\Section::toRenderArray()
    +   *
    +   * @var string
    +   */
    +  const SECTION_BUILD_REGIONS_ARRAY = 'section.build.regions_array';
    
    +++ b/core/modules/layout_builder/src/Section.php
    @@ -81,14 +83,21 @@ public function __construct($layout_id, array $layout_settings = [], array $comp
    +    // Build the regions array.
    +    $event = new SectionBuildRegionsArrayEvent($this->getComponents(), $this, $contexts, $in_preview);
    +    $event_dispatcher->dispatch(LayoutBuilderEvents::SECTION_BUILD_REGIONS_ARRAY, $event);
    

    We don't need this event at all. Let's follow the component similar approach. We only need to dispatch one event and provide a subscriber that builds the region array with a priority of 100. Then contrib is able to hook in before or after.

  4. +++ b/core/modules/layout_builder/src/Event/SectionBuildRenderArrayEvent.php
    @@ -0,0 +1,118 @@
    +  public function __construct(array $build, Section $section, array $contexts, $in_preview = FALSE) {
    

    Let's type $in_review to bool.

  5. +++ b/core/modules/layout_builder/src/Event/SectionBuildRenderArrayEvent.php
    @@ -0,0 +1,118 @@
    +  public function getSection() {
    ...
    +  public function getContexts() {
    ...
    +  public function getBuild() {
    ...
    +  public function setBuild(array $build) {
    
    +++ b/core/modules/layout_builder/src/EventSubscriber/SectionRegionsArray.php
    @@ -0,0 +1,44 @@
    +  public static function getSubscribedEvents() {
    ...
    +  public function onBuildRegions(SectionBuildRegionsArrayEvent $event) {
    
    +++ b/core/modules/layout_builder/src/Section.php
    @@ -315,6 +324,16 @@ public function insertComponent($delta, SectionComponent $new_component) {
    +  protected function eventDispatcher() {
    

    As this is new code we can strict type the return.

  6. +++ b/core/modules/layout_builder/src/Event/SectionBuildRenderArrayEvent.php
    @@ -0,0 +1,118 @@
    +  public function inPreview() {
    

    Maybe isInPreview()? And let's strict type the return to bool.

  7. +++ b/core/modules/layout_builder/src/Event/SectionBuildRenderArrayEvent.php
    @@ -0,0 +1,118 @@
    +    $this->build = $build;
    +  }
    

    Let's allow chaining, return $this.

claudiu.cristea’s picture

Title: Allow greater flexibility within Section::toRenderArray() » Third party should be allowed to alter the section render array
Issue summary: View changes

Improved IS.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea
Issue tags: -Needs issue summary update

Assigning to fix the issues.

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new13.65 KB
new7.04 KB

Fixing #8.2 & #20.


Still needs:

  • Tests
  • Change record
claudiu.cristea’s picture

StatusFileSize
new485 bytes
new8.75 KB

Fixing PHP CS.


Still needs:

  • Tests
  • Change record
claudiu.cristea’s picture

StatusFileSize
new6.97 KB
new485 bytes

It was a wrong patch.

Status: Needs review » Needs work

The last submitted patch, 25: 3062862-25.patch, failed testing. View results

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new3.82 KB
new10.79 KB

Fixing PHPUnit tests. I think it's OK that the new subscribers to be able to provide cache metadata.

claudiu.cristea’s picture

Development has been moved in drupal-3062862 fork, merge request !588.

Fixed the PHP CS failure from #27.

Still needs:


  • Tests
  • Change record
claudiu.cristea’s picture

Issue tags: -Needs tests

Added tests.


Still needs:

  • Change record
claudiu.cristea’s picture

Added CR: https://www.drupal.org/node/3210520. Ready for review.

claudiu.cristea’s picture

Issue tags: -Needs change record
claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
claudiu.cristea’s picture

Category: Task » Feature request

This looks more like a feature request.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea’s picture

I think that 3rd-party should also be aware about the section's delta. But how to pass that? Section::toRenderArray() doesn't own that info.

segovia94 made their first commit to this issue’s fork.

segovia94’s picture

Status: Needs review » Needs work

Somewhere along the way we lost one of the subscribers that allowed altering the final render array. Now it is only possible to alter the section regions and not the section itself. For example, if I want to add an attribute to the section like a new css class there is no longer a way to do this. The current event is dispatched before core/lib/Drupal/Core/Layout/LayoutDefault::build(), and that method strips out all data except previously declared regions. So trying to add an $regions['#attributes']['class'][] = 'my-custom-class' in the current event subscriber is useless since it is stripped out.

dsnopek’s picture

Somewhere along the way we lost one of the subscribers that allowed altering the final render array.

I think this goes back to #3062862-20: Third party should be allowed to alter the section render array when @claudiu.cristea started working on this and wrote (in point nr 3):

We don't need this event at all. Let's follow the component similar approach. We only need to dispatch one event and provide a subscriber that builds the region array with a priority of 100. Then contrib is able to hook in before or after.

In #3062862-23: Third party should be allowed to alter the section render array the event that modifies the render array is essentially removed (although, this is a little confusing to follow on the interdiff, because there it looks like the region event is removed, and then the render array one is converted to be about the regions :-))

Without this second event, it's impossible to implement component and region styles like in my sandbox module (https://www.drupal.org/sandbox/dsnopek/3059795). (EDIT: see next comment!)

However, @claudiu.cristea did a great job of modernizing this patch! So, probably best to try to add the missing event back in on top of the latest code here.

dsnopek’s picture

Status: Needs work » Needs review

Without this second event, it's impossible to implement component and region styles like in my sandbox module (https://www.drupal.org/sandbox/dsnopek/3059795).

I take that back! I thought my module was depending on the event that was removed, however, it turns out it depends on the other one. I just got the events all mixed up. :-)

So, I've rebased the issue fork, and ported my sandbox module to use the current code here.

@claudiu.cristea and @segovia94: Thanks for all the work you've put into this!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pbabin’s picture

In speaking with @segovia94 we may have an edge case where we need the event that was removed. We're working on trying to apply styles to sections. In some cases the styles are applied; however, in others they are not applied correctly. Specifically where we have a sections within a section. Styles are applied correctly in layout builder but do not display correctly when the page is rendered in view mode.
Layout Builder view
Screenshot of items not displaying
Page view
Missing default classes from block style plugins and the gold class even though it is not visually shown in the screenshots.
Page view

segovia94’s picture

Status: Needs review » Needs work

@pbabin I think I may have confused you. The problem you ran into is not related and is due to a workaround in the specific module created since this second event was removed from this issue. But yes, having the second event would fix the problem.

I can add back in the second event that was triggered after the build(). The other option is to edit the Drupal\Core\Layout\LayoutDefault::build() to add into the render array any properties passed into it. That's the biggest problem causing the existing event not to be as useful since it currently can only affect individual regions and not the overall section properties.

Also, I don't see a way to change the merge request to be against 9.4.x.

heddn’s picture

@claudiu.cristea can you rebase the MR on 9.4 please? Or at least change the target of the MR? As you created it, I think you have to change it.

claudiu.cristea’s picture

@heddn, done

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ldavidsp’s picture

StatusFileSize
new30.75 KB

Fixed for drupal 9.4.x

ldavidsp’s picture

StatusFileSize
new30.41 KB

Fixed for drupal 9.4.x

heddn’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 50: drupal-3062862-50.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new30.37 KB
new691 bytes

Fixing failed test of patch #50.

ldavidsp’s picture

StatusFileSize
new30.82 KB

Fixed hunk for LayoutBuilderEntityViewDisplay.php to drupal 9.4.x

edysmp’s picture

StatusFileSize
new33.92 KB
new3.69 KB

Added the `SectionBuildRenderArrayEvent` event that will allow us to alter the section's build render array while we still have access to the section's third party settings. e.g use case, add configurable CSS classes to the section's container div.

ravi.shankar’s picture

StatusFileSize
new33.98 KB
new1.51 KB

Fixed Drupal CS issues of patch #55.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

heddn’s picture

StatusFileSize
new33.14 KB
new34.26 KB

Re-roll for 10.1 and a 9.5 patch for applying on _those_ sites still.

heddn’s picture

StatusFileSize
new33.15 KB
new1.96 KB

Make drupalci happy.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

+ @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

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

heddn’s picture

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

milos.kroulik’s picture

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.

edysmp’s picture

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

$events[SectionBuildRenderArrayEvent::class] = ['onSectionBuildRender'];
graber’s picture

StatusFileSize
new33.48 KB

...

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

edysmp’s picture

rebased onto the main branch

graber changed the visibility of the branch 3062862-layout-3rd to hidden.

graber changed the visibility of the branch issue/drupal-3062862-3062862-layout-3rd to hidden.

graber changed the visibility of the branch 9.3.x to hidden.

graber changed the visibility of the branch 9.2.x to hidden.

graber’s picture

Status: Needs work » Needs review

Ok, all green and #60 addressed. Also hidden all previous branches so there is no confusion. Back to review.

graber’s picture

Status: Needs review » Reviewed & tested by the community

Since Lucas just reviewed and I addressed his feedback (deprecation msg update), moving this to RTBC.

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

Some comments on the MR.

graber’s picture

Status: Needs work » Reviewed & tested by the community

Thank you, all addressed. We have 2 tests failing now but both look unrelated (both from Drupal\FunctionalTests\DefaultContent\ContentExportTest).
Moving back to RTBC.
@godotislate pls check changing your BubbleableMetadata to CacheableMetadata just in case - added a comment on the MR.

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record updates

Glancing at the last changes I am not sure this should have been set back to RTBC. Typically a committer will explicitly say that is OK.

I also don't see any review of the change record and the last time it was updated was in 2022. So that needs a review as well. If nothing else the branch and version numbers needs an update.

quietone’s picture

Coming back to be more explicit.
The change record needs work because, at least, the version and branch are incorrect. Also, a change record should lead with the change. and the two code blocks, if still relevant, should have some text to explain what they are for. For reference, https://www.drupal.org/community/contributor-guide/task/write-a-change-record-for-a-drupal-core-issue

There were quite a few questions and suggestions by @godotislate. They seem to be answered but this is not my area and the GitLab UI is not showing some of the changes made so I can't confidently resolve 'easy' threads. One of the suggestions was to use BubbleableMetadataach, which does have a reply but has not been reviewed. At least, that needs review before being passed to the committers.

I hope that helps.

nicxvan’s picture

I do wonder if this is a better fit for an alter hook.

We typically do alters for stuff like this and we'd be able to expose it for themes. An event subscriber won't work in themes.

graber’s picture

Status: Needs work » Needs review

Here's a hook solution (MR 15723), also updated the change record. There may be test failures but I tested current main and unfortunately those were pre-existing so someone is breaking things on main.
Moving to review, if any minor issues (phpstan baseline sort for example), I'll update on the fly.

heddn’s picture

re #79: We should consider though that LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY is already a thing in almost the same space. Offering one via event subscriber and the other in hook alter seems confusing.

graber’s picture

True but I agree a hook will fit better here, that’s why I did it. We can have a follow up to convert the other one to an event and I can handle it too, not a very difficult change.

nicxvan’s picture

Yeah, I think this is something that themes will want to interact with, the right answer is likely a hook and deprecating those other events to hooks as well.