function EntityAdapter::createFromEntity

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::createFromEntity()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::createFromEntity()
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::createFromEntity()

Creates an instance wrapping the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface|null $entity: The entity object to wrap.

Return value

static

6 calls to EntityAdapter::createFromEntity()
CKEditor5ImageController::validate in core/modules/ckeditor5/src/Controller/CKEditor5ImageController.php
Validates the file.
EntityAdapterUnitTest::setUp in core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
EntityContextDefinition::getSampleValues in core/lib/Drupal/Core/Plugin/Context/EntityContextDefinition.php
Returns typed data objects representing this context definition.
RecursiveContextualValidatorTest::testRecursiveValidate in core/tests/Drupal/KernelTests/Core/TypedData/RecursiveContextualValidatorTest.php
Tests recursive validation against given constraints against an entity.
TemporaryJsonapiFileFieldUploader::handleFileUploadForField in core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php
Creates and validates a file entity for a file field from a file stream.

... See full list

File

core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php, line 46

Class

EntityAdapter
Defines the "entity" data type.

Namespace

Drupal\Core\Entity\Plugin\DataType

Code

public static function createFromEntity(EntityInterface $entity) {
    $definition = EntityDataDefinition::create()->setEntityTypeId($entity->getEntityTypeId())
        ->setBundles([
        $entity->bundle(),
    ]);
    $instance = new static($definition);
    $instance->setValue($entity);
    return $instance;
}

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