function EntityContext::fromEntity
Gets a context object from an entity.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: Entity that provides a context.
string $label: (optional) The label of the context.
Return value
static
8 calls to EntityContext::fromEntity()
- CurrentUserContext::getRuntimeContexts in core/
modules/ user/ src/ ContextProvider/ CurrentUserContext.php - Gets runtime context values for the given context IDs.
- DefaultsSectionStorage::deriveContextsFromRoute in core/
modules/ layout_builder/ src/ Plugin/ SectionStorage/ DefaultsSectionStorage.php - Derives the available plugin contexts from route values.
- DefaultsSectionStorage::getContextsDuringPreview in core/
modules/ layout_builder/ src/ Plugin/ SectionStorage/ DefaultsSectionStorage.php - Gets contexts for use during preview.
- LayoutBuilderEntityViewDisplay::buildSections in core/
modules/ layout_builder/ src/ Entity/ LayoutBuilderEntityViewDisplay.php - Builds the render array for the sections of a given entity.
- LayoutBuilderEntityViewDisplay::getContextsForEntity in core/
modules/ layout_builder/ src/ Entity/ LayoutBuilderEntityViewDisplay.php - Gets the available contexts for a given entity.
File
-
core/
lib/ Drupal/ Core/ Plugin/ Context/ EntityContext.php, line 56
Class
- EntityContext
- Class to provide a specific entity context.
Namespace
Drupal\Core\Plugin\ContextCode
public static function fromEntity(EntityInterface $entity, $label = NULL) {
$context = static::fromEntityType($entity->getEntityType(), $label);
$context->setContextValue($entity);
return $context;
}