function EntityContext::fromEntity

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\EntityContext::fromEntity()
  2. 10 core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\EntityContext::fromEntity()
  3. 11.x core/lib/Drupal/Core/Plugin/Context/EntityContext.php \Drupal\Core\Plugin\Context\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

28 calls to EntityContext::fromEntity()
ConditionTestDualUserTest::doTestDifferentUser in core/tests/Drupal/KernelTests/Core/Plugin/Condition/ConditionTestDualUserTest.php
Tests with each context mapped to different users.
ConditionTestDualUserTest::doTestIdenticalUser in core/tests/Drupal/KernelTests/Core/Plugin/Condition/ConditionTestDualUserTest.php
Tests with both contexts mapped to the same user.
ContextDefinitionTest::testIsSatisfiedBy in core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php
@covers ::isSatisfiedBy
ContextHandlerTest::testApplyContextMapping in core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php
@covers ::applyContextMapping
ContextHandlerTest::testApplyContextMappingAlreadyApplied in core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php
@covers ::applyContextMapping

... 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.