You are here

public static function SingleInternalPropertyTestFieldItem::propertyDefinitions in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/SingleInternalPropertyTestFieldItem.php \Drupal\entity_test\Plugin\Field\FieldType\SingleInternalPropertyTestFieldItem::propertyDefinitions()

Defines field item properties.

Properties that are required to constitute a valid, non-empty item should be denoted with \Drupal\Core\TypedData\DataDefinition::setRequired().

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An array of property definitions of contained properties, keyed by property name.

Overrides StringItemBase::propertyDefinitions

See also

\Drupal\Core\Field\BaseFieldDefinition

File

core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/SingleInternalPropertyTestFieldItem.php, line 34

Class

SingleInternalPropertyTestFieldItem
Defines the 'Single Internal Property' entity test field type.

Namespace

Drupal\entity_test\Plugin\Field\FieldType

Code

public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
  $properties = parent::propertyDefinitions($field_definition);

  // Add a computed property that is internal.
  $properties['internal_value'] = DataDefinition::create('string')
    ->setLabel(new TranslatableMarkup('Computed string, internal property'))
    ->setComputed(TRUE)
    ->setClass(ComputedString::class);
  return $properties;
}