Problem/Motivation

There is not a uniform way to get layout sections for an entity

right now if you have todo something like

if ($entity->getEntityTypeId() === 'entity_view_display' && $entity instanceof LayoutBuilderEntityViewDisplay) {
      return $entity->getSections();
    }
    elseif ($this->isEntityUsingFieldOverride($entity)) {
      return $entity->get('layout_builder__layout')->getSections();
    }

Proposed resolution

make it simplier.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 2986403-lbtrait-3.patch12.17 KBtim.plunkett

Comments

tedbow created an issue. See original summary.

phenaproxima’s picture

I think this should be done using the context system, as in #2976148: Layout-based entity rendering should delegate to the correct section storage instead of hardcoding to either defaults or overrides. I will roll a patch based on that work.

The idea here is that, given N section storage plugins, you have to find one that will accept an entity and derive a list of sections from it. "Which plugin to use, given this entity" is a perfect use case for contexts. So to load sections from an entity, it would be something like this:

$contexts = [
  'entity' => EntityContext::fromEntity($entity),
];
$plugin_definitions = $section_storage_manager->getDefinitionsForContexts($contexts);
$plugin_id = key($plugin_definitions);
$plugin = $section_storage_manager->createInstance($plugin_id);
$plugin->setContexts($contexts);

$section_list = $plugin->getSectionListFromContext();

We could add a utility method to SectionStorageManagerInterface to streamline this (something like loadFromEntity()).

tim.plunkett’s picture

Postponing this, but here's a patch built on the other issue.

damienmckenna’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Status: Needs work » Closed (duplicate)
Issue tags: -sprint
Related issues: +#3026434: Ensure that Layout Builder Inline Blocks doesn't assume section storage internals

Marking this as a duplicate