public function deriveContextsFromRoute($value,
$definition,
$name, array
$defaults) { $contexts =
[];
if ($entity =
$this->
extractEntityFromRoute($value,
$defaults)) { $contexts['entity'
] = EntityContext::
fromEntity($entity);
// @todo Expand to work for all view modes in
// https://www.drupal.org/node/2907413.
$view_mode = 'full';
// Retrieve the actual view mode from the returned view display as the
// requested view mode may not exist and a fallback will be used.
$view_mode = LayoutBuilderEntityViewDisplay::
collectRenderDisplay($entity,
$view_mode)->
getMode();
$contexts['view_mode'
] =
new Context(new ContextDefinition('string'
),
$view_mode);
} return $contexts;
} /**
* Extracts an entity from the route values.
*
* @param mixed $value
* The raw value from the route.
* @param array $defaults
* The route defaults array.
*
* @return \Drupal\Core\Entity\EntityInterface|null
* The entity for the route, or NULL if none exist.
*
* @see \Drupal\layout_builder\SectionStorageInterface::deriveContextsFromRoute()
* @see \Drupal\Core\ParamConverter\ParamConverterInterface::convert()
*/