- πͺπΈSpain akalam
I come into this issue in the following scenario using the "group" module.
We are using the group content entity to render the full view mode of the node, and we are using layout builder on the nodes. The problem is with the blocks that have group context, because the run time contexts are not selectable on the block config form because we don't have the context of the group populated (since we are on the layout builder of a node), but the context of the group will be populated properly when viewing the node because it's gonna be rendered within the group content entity, and therefore accessed within a route with the group context.The general idea is that not having the context populated on layout builder doesn't mean that the context won't be populated when viewing that entity. Filtering the contexts based on that precept will make layout builder less functional compared to the block layout, where no contexts are populated and they are not filtered.
I'm uploading a simple patch just removing that filtering so all contexts will be available to select.
- πͺπΈSpain akalam
Even when the previous patch was avoiding layout builder to filter some contexts, many context definitions are not complete (for example they don't have label). For this reason when having different contexts for the same entity type, they use the entity type name instead of the context label.
Calling the method getAvailableContexts() instead is doing the trick, and now the labels are properly setup. Among that, is more performative to call just the available context and not the runtime contexts if we are not going to take care if the context is populated or not.
- πͺπΈSpain akalam
The previous patches had a side effect: When you are trying to add a block on a node, the node fields for all content types are available which is not nice. On the other hand, according to the name of the method "getPopulatedContexts()", make sense how it works, using the runtime context instead of the available contexts.
Therefore I've changed the approach, and I'm getting the available context only on the \Drupal\layout_builder\Form\ConfigureBlockFormBase::doBuildForm
- πΊπΈUnited States smustgrave
So patches should be in MRs now
And will need test coverage
Thanks!
- Merge request !9918Issue #3194198: Contexts without data not visible in block context selector β (Open) created by akalam
- πͺπΈSpain akalam
I've found an issue when trying to add a entity field block on layout builder. Seems like the best solution is to filter for the contexts that are both required and empty, so non required contexts are still available.
I'm adding a MR instead of a static patch.