Version 1
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Entity / EntityTestBaseFieldDisplay.php
1 <?php
2
3 namespace Drupal\entity_test\Entity;
4
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Field\BaseFieldDefinition;
7 use Drupal\entity_test\FieldStorageDefinition;
8
9 /**
10  * Defines a test entity class for base fields display.
11  *
12  * @ContentEntityType(
13  *   id = "entity_test_base_field_display",
14  *   label = @Translation("Test entity - base field display"),
15  *   handlers = {
16  *     "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
17  *     "form" = {
18  *       "default" = "Drupal\entity_test\EntityTestForm"
19  *     },
20  *     "translation" = "Drupal\content_translation\ContentTranslationHandler",
21  *     "route_provider" = {
22  *       "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
23  *     },
24  *   },
25  *   base_table = "entity_test_base_field_display",
26  *   admin_permission = "administer entity_test content",
27  *   entity_keys = {
28  *     "id" = "id",
29  *     "label" = "name",
30  *     "uuid" = "uuid",
31  *     "bundle" = "type",
32  *     "langcode" = "langcode",
33  *   },
34  *   links = {
35  *     "canonical" = "/entity_test_base_field_display/{entity_test_base_field_display}/edit",
36  *     "add-form" = "/entity_test_base_field_display/add",
37  *     "edit-form" = "/entity_test_base_field_display/manage/{entity_test_base_field_display}",
38  *     "delete-form" = "/entity_test/delete/entity_test_base_field_display/{entity_test_base_field_display}/edit",
39  *   },
40  *   field_ui_base_route = "entity.entity_test_base_field_display.admin_form",
41  * )
42  */
43 class EntityTestBaseFieldDisplay extends EntityTest {
44
45   /**
46    * {@inheritdoc}
47    */
48   public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
49     $fields = parent::baseFieldDefinitions($entity_type);
50
51     $fields['test_no_display'] = BaseFieldDefinition::create('text')
52       ->setLabel(t('Field with no display'));
53
54     $fields['test_display_configurable'] = BaseFieldDefinition::create('text')
55       ->setLabel(t('Field with configurable display'))
56       ->setDisplayOptions('view', [
57         'type' => 'text_default',
58         'weight' => 10,
59       ])
60       ->setDisplayConfigurable('view', TRUE)
61       ->setDisplayOptions('form', [
62         'type' => 'text_textfield',
63         'weight' => 10,
64       ])
65       ->setDisplayConfigurable('form', TRUE);
66
67     $fields['test_display_non_configurable'] = BaseFieldDefinition::create('text')
68       ->setLabel(t('Field with non-configurable display'))
69       ->setDisplayOptions('view', [
70         'type' => 'text_default',
71         'weight' => 11,
72       ])
73       ->setDisplayOptions('form', [
74         'type' => 'text_textfield',
75         'weight' => 11,
76       ]);
77
78     $fields['test_display_multiple'] = BaseFieldDefinition::create('text')
79       ->setLabel(t('A field with multiple values'))
80       ->setCardinality(FieldStorageDefinition::CARDINALITY_UNLIMITED)
81       ->setDisplayOptions('view', [
82         'type' => 'text_default',
83         'weight' => 12,
84       ])
85       ->setDisplayOptions('form', [
86         'type' => 'text_textfield',
87         'weight' => 12,
88       ]);
89
90     return $fields;
91   }
92
93 }