Problem/Motivation

Subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections and load the sections from the field added in #2941806: Create an ER field to store reference to the chosen layout on the content entity.

Implement hook_entity_type_alter() and swap in our class instead of layout builder's

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

larowlan created an issue. See original summary.

larowlan’s picture

Title: subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections » Subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections
andypost’s picture

Could it be moved to trait or some event?

larowlan’s picture

Looks like hook_entity_view_alter is enough here

phenaproxima’s picture

Version: » 8.x-1.x-dev

How will we go about subclassing LayoutBuilderEntityViewDisplay in a reliable manner? It's already brought in during a hook_entity_type_alter (Layout Builder's implementation), which means the only way we could guarantee that our subclass gets used is to implement the very evil hook_module_implements_alter, which should be a last resort.

I propose an alternate approach:

  1. We implement #2941806: Create an ER field to store reference to the chosen layout on the content entity such that an entity reference field, referring to the Layout entity type, is automagically created for all overrideable layouts.
  2. Implement hook_entity_presave() and copy the referenced layout sections into the entity's layout override field as needed.

Layout Builder will then respect the override data without us needing to subclass anything at all. What say you to this approach?

phenaproxima’s picture

Title: Subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections » [PP-1] Subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections
Status: Active » Postponed
larowlan’s picture

Implement hook_entity_presave() and copy the referenced layout sections into the entity's layout override field as needed.

Sounds like a plan

jibran’s picture

Title: [PP-1] Subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections » Subclass \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getRuntimeSections
Status: Postponed » Active

Blocker is in.

tim.plunkett’s picture

This is a workaround for #2976148: Layout-based entity rendering should delegate to the correct section storage instead of hardcoding to either defaults or overrides, where we have been putting in effort instead. Not sure if this is worth continuning with that progress?

phenaproxima’s picture

Status: Active » Closed (outdated)

Let's just fix it in core.