You are here

public function FieldItemBase::__construct in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/FieldItemBase.php \Drupal\Core\Field\FieldItemBase::__construct()
  2. 9 core/lib/Drupal/Core/Field/FieldItemBase.php \Drupal\Core\Field\FieldItemBase::__construct()

Constructs a TypedData object given its definition and context.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $definition: The data definition.

string $name: (optional) The name of the created property, or NULL if it is the root of a typed data tree. Defaults to NULL.

\Drupal\Core\TypedData\TypedDataInterface $parent: (optional) The parent object of the data property, or NULL if it is the root of a typed data tree. Defaults to NULL.

Overrides TypedData::__construct

See also

\Drupal\Core\TypedData\TypedDataManager::create()

1 method overrides FieldItemBase::__construct()
FieldTestItem::__construct in core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php
Constructs a TypedData object given its definition and context.

File

core/lib/Drupal/Core/Field/FieldItemBase.php, line 46

Class

FieldItemBase
An entity field item.

Namespace

Drupal\Core\Field

Code

public function __construct(ComplexDataDefinitionInterface $definition, $name = NULL, TypedDataInterface $parent = NULL) {
  parent::__construct($definition, $name, $parent);

  // Initialize computed properties by default, such that they get cloned
  // with the whole item.
  foreach ($this->definition
    ->getPropertyDefinitions() as $name => $definition) {
    if ($definition
      ->isComputed()) {
      $this->properties[$name] = \Drupal::typedDataManager()
        ->getPropertyInstance($this, $name);
    }
  }
}