2bc8154cf9e9605c06ee0d7260234ed698e74000
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / FieldType / InternalPropertyTestFieldItem.php
1 <?php
2
3 namespace Drupal\entity_test\Plugin\Field\FieldType;
4
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;
10
11 /**
12  * Defines the 'Internal Property' entity test field type.
13  *
14  * @FieldType(
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"
21  * )
22  */
23 class InternalPropertyTestFieldItem extends StringItem {
24
25   /**
26    * {@inheritdoc}
27    */
28   public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
29     $properties = parent::propertyDefinitions($field_definition);
30
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'))
34       ->setComputed(TRUE)
35       ->setClass(ComputedString::class)
36       ->setInternal(FALSE);
37     // Add a computed property that is internal.
38     $properties['internal_value'] = DataDefinition::create('string')
39       ->setLabel(new TranslatableMarkup('Computed string, internal property'))
40       ->setComputed(TRUE)
41       ->setClass(ComputedString::class);
42     return $properties;
43   }
44
45 }