Problem/Motivation

layout_builder_is_active cache context implemented in \Drupal\layout_builder\Cache\LayoutBuilderIsActiveCacheContext does not seem to be providing the correct cache context value - it is always 0. Issues seem to be:

  • getContext() calls getDisplay(). getDisplay()checks whether the entity parameter from the route is an instance of OverridesSectionStorageInterface. AFAICT, OverridesSectionStorageInterface is not implemented by any entity classes; it's just the interface for the overrides section storage plugin. In which case, getDisplay() always returns NULL.
  • Docblock for getDisplay() says the method should return \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface, but even assuming there is an entity implementing OverridesSectionStorageInterface, getDefaultSectionStorage() returns \Drupal\layout_builder\DefaultsSectionStorageInterface, not \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface
  • Class docblock says that the cache context is to be used to "Determines whether Layout Builder is active for a given entity type or not.", but it seems the intent of the code is to determine whether a specific entity has layout builder overrides enabled.
  • There isn't any test coverage for this cache context.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

godotislate created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new4.53 KB
new6.08 KB

Well spotted. I don't know how we ended up with that code back when we wrote it! Tests sure would have helped.

tim.plunkett’s picture

StatusFileSize
new4.53 KB
new6.07 KB
new625 bytes

Oops, blank line.

The last submitted patch, 3: 3190541-cache-3-FAIL.patch, failed testing. View results

godotislate’s picture

Nice work! My only nit is that I think the class docblock is not quite accurate about what the cache context is for, or at least, there should be clarification that "layout builder is active" means that the current route entity has overridable layout display.

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.

tim.plunkett’s picture

Version: 9.3.x-dev » 9.4.x-dev
StatusFileSize
new6.46 KB
new855 bytes

Adjusted the docblock, thanks

clayfreeman’s picture

Status: Needs review » Reviewed & tested by the community
godotislate’s picture

+1 for RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 3190541-cache-7.patch, failed testing. View results

clayfreeman’s picture

Status: Needs work » Reviewed & tested by the community

Test failure appears to be transient; resetting RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 3190541-cache-7.patch, failed testing. View results

godotislate’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC

  • catch committed 3ea2660 on 10.0.x
    Issue #3190541 by tim.plunkett, godotislate, clayfreeman:...

  • catch committed 697c1d8 on 9.4.x
    Issue #3190541 by tim.plunkett, godotislate, clayfreeman:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.0.x and cherry-picked to 9.4.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.