Layout builder incorrectly assumes it can get global contexts and values with getAvailableContexts. This means context providers that correctly adhere to \Drupal\Core\Plugin\Context\ContextProviderInterface
currently do not resolve values with layout builder.
When rendering layouts, \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::getContextsForEntity
should call contextRepository->getRuntimeContexts
on the result of contextRepository->getAvailableContexts
since by design the value are not intended to be added in getAvailableContexts.
It so happens the CurrentLanguageContext
and CurrentUserContext
incorrectly populate values in getAvailableContexts, which likely lead to this unnoticed issue. The way these context providers are allowing empty arrays to be passed to getRuntimeContexts
is cheating. Even the contract for \Drupal\Core\Plugin\Context\ContextProviderInterface::getRuntimeContexts
specifies only those provided must be returned. The attach patch basically does the empty-array cheat on contexts, but using the API as specified.
Contexts like NodeRouteContext
correctly implement the interface, and could be made to work with LB. Currently this context also doesnt work properly because it doesnt set a default context value on layout builder build pages (See \Drupal\layout_builder\Context\LayoutBuilderContextTrait::getAvailableContexts
). Note, solving NodeRouteContext
is not within scope of this bug.
See the documentation for \Drupal\Core\Plugin\Context\ContextProviderInterface::getAvailableContexts
, and the interface in general, for more information.