Layout Builder overrides section storage sets local tasks block cache max-age to 0 on content entity pages without overrides enabled

Created on 31 December 2020, over 3 years ago
Updated 8 February 2024, 4 months ago

Problem/Motivation

\Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage provides local tasks for relevant entity types.

When viewing an entity of one of those types (let's just say node for simplicity), if overrides aren't enabled for the display for that node, as the links for the local tasks are built, the access for the layout_builder.overrides.node.view link has max-age 0. This max-age is applied to the local task block render array.

The reason this is happening is that as the local tasks are built, access to each link is checked via \Drupal\Core\Access\AccessManager::checkNamedRoute(). In that method, the route parameters for the layout_builder.overrides.node.view are upcasted, but since there is no overrides section storage for the entity, \Drupal\layout_builder\Routing\LayoutTempstoreParamConverter returns NULL for the section storage parameter, causing
\Drupal\Core\ParamConverter\ParamConverterManager::convert() to throw. ParamNotConvertedException
The exception is handled by the access manager by denying access and setting the access object cache max-age 0.

Since the local tasks block will vary by permissions and by each page anyway, making the block uncacheable is probably not wrong. However, it would affect page/response cacheability in #2352009: [pp-3] Bubbling of elements' max-age to the page's headers and the page cache β†’ .

Steps to reproduce

  1. Install Standard profile
  2. Install Layout Builder. Do not enable on any content type displays
  3. Create an Article
  4. Set container parameterhttp.response.debug_cacheability_headers to true
  5. View page for the created Article node and confirm X-Drupal-Cache-Max-Age header is "0 (Uncacheable)"
  6. Enable Layout Builder and overrides for Basic Page default display
  7. Create new Basic Page
  8. Visit new Basic Page and confirm X-Drupal-Cache-Max-Age header is "-1 (Permanent)"
  9. View page for the created Article node again and confirm X-Drupal-Cache-Max-Age header is still "0 (Uncacheable)"

Proposed resolution

Per #22 πŸ› Layout Builder overrides section storage sets local tasks block cache max-age to 0 on content entity pages without overrides enabled RTBC

  1. Don't gate ::extractEntityFromRoute() on the entity being fieldable, or having the override layout storage field. It would seem more appropriate to add a separate method for these checks if necessary (though I don't believe it to be necessary).
  2. Only permit access to the override layout section storage if the default section storage specifies that overrides are enabled. This will appropriately prevent access to the override layout editing route since LayoutBuilderAccessCheck already defers to section storage-specific access checks.

Remaining tasks

Review

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

TBD

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
Layout builderΒ  β†’

Last updated about 10 hours ago

Created by

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

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

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.

Production build 0.69.0 2024