Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EntityContext.php

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.

... See full list

File

core/lib/Drupal/Core/Plugin/Context/EntityContext.php, line 56

Class

EntityContext
Class to provide a specific entity context.

Namespace

Drupal\Core\Plugin\Context

Code

public static function fromEntity(EntityInterface $entity, $label = NULL) {
    $context = static::fromEntityType($entity->getEntityType(), $label);
    $context->setContextValue($entity);
    return $context;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal