3 namespace Drupal\entity_test\Plugin\Field\FieldType;
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\Core\Field\Plugin\Field\FieldType\StringItem;
7 use Drupal\Core\StringTranslation\TranslatableMarkup;
8 use Drupal\Core\TypedData\DataDefinition;
9 use Drupal\entity_test\TypedData\ComputedString;
12 * Defines the 'Internal Property' entity test field type.
15 * id = "internal_property_test",
16 * label = @Translation("Internal Property (test)"),
17 * description = @Translation("A field containing one string, from which two strings are computed (one internal, one not)."),
18 * category = @Translation("Test"),
19 * default_widget = "string_textfield",
20 * default_formatter = "string"
23 class InternalPropertyTestFieldItem extends StringItem {
28 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
29 $properties = parent::propertyDefinitions($field_definition);
31 // Add a computed property that is non-internal.
32 $properties['non_internal_value'] = DataDefinition::create('string')
33 ->setLabel(new TranslatableMarkup('Computed string, non-internal property'))
35 ->setClass(ComputedString::class)
37 // Add a computed property that is internal.
38 $properties['internal_value'] = DataDefinition::create('string')
39 ->setLabel(new TranslatableMarkup('Computed string, internal property'))
41 ->setClass(ComputedString::class);