function FieldConfigBase::getItemDefinition

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::getItemDefinition()
  2. 10 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::getItemDefinition()
  3. 9 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::getItemDefinition()
  4. 8.9.x core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::getItemDefinition()

File

core/lib/Drupal/Core/Field/FieldConfigBase.php, line 554

Class

FieldConfigBase
Base class for configurable field definitions.

Namespace

Drupal\Core\Field

Code

public function getItemDefinition() {
  if (!isset($this->itemDefinition)) {
    $this->itemDefinition = FieldItemDataDefinition::create($this)->setSettings($this->getSettings());
    // Add any custom property constraints, overwriting as required.
    $item_constraints = $this->getItemDefinition()
      ->getConstraint('ComplexData')['properties'] ?? [];
    foreach ($this->propertyConstraints as $name => $constraints) {
      if (isset($item_constraints[$name])) {
        $item_constraints[$name] = $constraints + $item_constraints[$name];
      }
      else {
        $item_constraints[$name] = $constraints;
      }
      $this->itemDefinition
        ->addConstraint('ComplexData', [
        'properties' => $item_constraints,
      ]);
    }
  }
  return $this->itemDefinition;
}

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