Problem/Motivation

Empty sections create unnecessary markup. Also, if you've styled the sections with a background/padding you'll get some unwanted bars.

Proposed resolution

Remove empty sections while preserving their cache metadata.

Remaining tasks

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

Issue fork drupal-3065418

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

Corn696 created an issue. See original summary.

corn696’s picture

StatusFileSize
new6.41 KB

Patch to add the render filter to the layout twigs.

tim.plunkett’s picture

corn696’s picture

hmm okay the issue exist nearly 9 years. So what is the best "temporary" workaround?

I copied the layout templates to my theme and added the render filter. Is there a better solution?

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.

tim.plunkett’s picture

Category: Task » Bug report
Issue summary: View changes
Status: Active » Needs review
Issue tags: +Blocks-Layouts
StatusFileSize
new2.54 KB
new4.73 KB

The render filter is a good temporary solution.
Here's one possible long-term fix.

Status: Needs review » Needs work

The last submitted patch, 6: 3065418-emptysections-6-PASS.patch, failed testing. View results

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.

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.

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.

tim.plunkett’s picture

Rebased and switched to using an MR

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.

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.

javier_rey’s picture

StatusFileSize
new2.35 KB

Adding a patch for the 10.1.x branch.

tim.plunkett’s picture

Status: Needs work » Needs review

Fixed a couple more tests

smustgrave’s picture

Status: Needs review » Needs work

Thank you for this! See this often with clients who aren’t great with layout builder.

Still seem to be some test failures however. Definitely keeping this on the radar

smustgrave’s picture

Status: Needs work » Needs review

@tim.plunkett added a condition so the sections do build in layout builder side.

Thoughts?

smustgrave’s picture

Status: Needs review » Needs work

Thanks. Also seemed to cause some additional test failures that I'll look at.

smustgrave’s picture

Status: Needs work » Needs review

So this additional checks seems to be the best way to cover all scenarios.

When adding a section _layout_builder isn't there.

Tried _admin_route but that caused test failures also.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

Fixing merge (using rebase) to allow me to review better

smustgrave’s picture

@tim.plunkett wonder if you had a chance to review?

tim.plunkett’s picture

I'll have to re-review, the change to checking for `layout_builder_tempstore` is tricky

smustgrave’s picture

Status: Needs review » Needs work

Tried this out on a local project and I use drush search-api-index

But I get this error

> [error] Error while trying to render item entity:node/48:en with view mode full for search index tetra_tech: Call to a member function getOption() on null in Drupal\Core\Layout\LayoutDefault->build() (line 70 of /var/www/html/webroot/core/lib/Drupal/Core/Layout/LayoutDefault.php).

So seems all scenarios aren't caught.

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.

leoenriquezp’s picture

StatusFileSize
new17.88 KB

Adding a patch for the 10.2.x branch

tonibarbera’s picture

StatusFileSize
new18.12 KB

Rerolled the patch for the 10.3.1 branch

krishna mishra’s picture

I get same error for media on solr indexing:
[error] Error while trying to render item entity:media/XX:en with view mode search_index for search index INDEX-ABC: Call to a member function getOption() on null in Drupal\Core\Layout\LayoutDefault->build() (line 70 of web/core/lib/Drupal/Core/Layout/LayoutDefault.php).

bbrala credited test.

bbrala’s picture

bbrala’s picture

bbrala’s picture

Sorry for the noise, tool a random issue to check something. Please ignore.

xjkwak’s picture

StatusFileSize
new18.15 KB

I encountered the same issue described in #29 when applying the patch from #28. The problem occurs because \Drupal::routeMatch()->getRouteObject() returns null in non-route contexts (e.g., during Search API indexing via cron), which leads to a fatal error when getOption() is called.

To fix this, I updated the patch to use the null-safe operator, ensuring the code does not break when the route object is unavailable:

$temp_store = FALSE;
if (!empty(\Drupal::routeMatch()?->getRouteObject()?->getOption('parameters')) &&
    isset(\Drupal::routeMatch()?->getRouteObject()?->getOption('parameters')['section_storage'])) {
  $temp_store = \Drupal::routeMatch()->getRouteObject()->getOption('parameters')['section_storage']['layout_builder_tempstore'];
}

This change ensures compatibility with CLI and cron environments. I've also attached an updated patch that includes this fix. It's my first contribution to Drupal :)

akalam’s picture

StatusFileSize
new16.86 KB

Rerolled against 11.3.x

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.