function EntityAdapter::createFromEntity

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php \Drupal\Core\Entity\Plugin\DataType\EntityAdapter::createFromEntity()
  2. 8.9.x 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()
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.
FieldConfigEditForm::getTypedData in core/modules/field_ui/src/Form/FieldConfigEditForm.php
Gets typed data object for the field.
FieldStorageConfig::getOptionsProvider in core/modules/field/src/Entity/FieldStorageConfig.php
Gets an options provider for the given field item property.
FieldStorageConfigEditForm::form in core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
Gets the actual form array to be built.

... See full list

File

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

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.