public function FieldItemBase::__construct

Implements TypedDataInterface::__construct().

Overrides TypedData::__construct

File

drupal/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php, line 57
Definition of Drupal\Core\Entity\Field\FieldItemBase.

Class

FieldItemBase
An entity field item.

Namespace

Drupal\Core\Entity\Field

Code

public function __construct(array $definition) {
  $this->definition = $definition;

  // Initialize all property objects, but postpone the creating of computed
  // properties to a second step. That way computed properties can safely get
  // references on non-computed properties during construction.
  $step2 = array();
  foreach ($this
    ->getPropertyDefinitions() as $name => $definition) {
    if (empty($definition['computed'])) {
      $context = array(
        'name' => $name,
        'parent' => $this,
      );
      $this->properties[$name] = typed_data()
        ->create($definition, NULL, $context);
    }
    else {
      $step2[$name] = $definition;
    }
  }
  foreach ($step2 as $name => $definition) {
    $context = array(
      'name' => $name,
      'parent' => $this,
    );
    $this->properties[$name] = typed_data()
      ->create($definition, NULL, $context);
  }
}