PageTitle block is non-functional when not handled directly by \Drupal\block\Plugin\DisplayVariant\BlockPageVariant

Created on 19 January 2018, almost 7 years ago
Updated 21 January 2024, 11 months ago

Problem/Motivation

Page titles in Drupal are determined in two different ways.
One is via the title_resolver service, which delegates to the route.
The other is by inspecting the render array of the main content of the page for a top-level #title key.

While the first approach can be used by any code in Drupal, the #title approach is only available at the very end of the rendering process.
The only code that gets access to the real title is whichever @PageDisplayVariant plugin is used to render the page.

The block.module provides a @PageDisplayVariant plugin that passes on the title directly to the page_title_block block.

Without any code setting the title directly on that block, it will always print an empty string.

Since there can only be one @PageDisplayVariant plugin selected at a time, this means that only one module can have access to the true actual title (in the case of a #title being used).

Proposed resolution

There are two approaches to be considered here.

First, the page_title_block block should use the title_resolver service as a fallback when setTitle() is not called.
This still allows the block.module usecase to properly respect the #title if applicable.
All non-block.module usages will not have that title, but the routing-based title.

This is acceptable as using the page title block within Layout Builder is rare, and using a top-level #title is also very rare, and unlikely to occur on a page using Layout Builder.

Furthermore, with #2359901: Discourage $main_content['#title'] in favor of route titles and title callbacks β†’ as a major task, eventually the #title approach will no longer be used.

If this approach is not acceptable, then Layout Builder can use hook_plugin_filter_TYPE__CONSUMER_alter() to remove the page title block from being placeable by Layout Builder. Each contrib solution that also has encountered this problem will also have to implement that hook for their own CONSUMER case.

Remaining tasks

Get sign-off on the proposed resolution above, or abandon it for the backup solution.

User interface changes

The page title block will function the same as before for block.module usages.
For alternate usages, the block will no longer be empty. It will contain the title for that route. It will not display the correct title if the top-level render array contains a #title key (aka Views Pages).

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Postponed

Version

11.0 πŸ”₯

Component
BlockΒ  β†’

Last updated 2 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States eclipsegc

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

  • Needs subsystem maintainer review

    It is used to alert the maintainer(s) of a particular core subsystem that an issue significantly impacts their subsystem, and their signoff is needed (see the governance policy draft for more information). Also, if you use this tag, make sure the issue component is set to the correct subsystem. If an issue significantly impacts more than one subsystem, use needs framework manager review instead.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024