You are here

public static function InternalPropertyTestFieldItem::propertyDefinitions in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/InternalPropertyTestFieldItem.php \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::propertyDefinitions()
  2. 9 core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/InternalPropertyTestFieldItem.php \Drupal\entity_test\Plugin\Field\FieldType\InternalPropertyTestFieldItem::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/InternalPropertyTestFieldItem.php, line 28

Class

InternalPropertyTestFieldItem
Defines the '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 non-internal.
  $properties['non_internal_value'] = DataDefinition::create('string')
    ->setLabel(new TranslatableMarkup('Computed string, non-internal property'))
    ->setComputed(TRUE)
    ->setClass(ComputedString::class)
    ->setInternal(FALSE);

  // 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;
}