function FieldConfigBase::getItemDefinition

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

Gets the data definition of an item of the list.

Return value

\Drupal\Core\TypedData\DataDefinitionInterface A data definition describing the list items.

Overrides ListDataDefinitionInterface::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.
    $complex_data_constraint = $this->getItemDefinition()
      ->getConstraint('ComplexData') ?: [];
    $item_constraints = $complex_data_constraint['properties'] ?? NULL;
    if ($item_constraints === NULL) {
      @trigger_error('Adding the "ComplexData" constraint with options missing the "properties" key is deprecated in drupal:11.4.0 and will not be supported in drupal:12.0.0. See https://www.drupal.org/node/3554746');
      $item_constraints = $complex_data_constraint;
    }
    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.