Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / tests / modules / entity_module_test / src / Entity / EnhancedEntity.php
1 <?php
2
3 namespace Drupal\entity_module_test\Entity;
4
5 use Drupal\Core\Entity\EntityPublishedInterface;
6 use Drupal\Core\Entity\EntityPublishedTrait;
7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Field\BaseFieldDefinition;
9 use Drupal\entity\Revision\RevisionableContentEntityBase;
10
11 /**
12  * Provides a test entity which uses all the capabilities of entity module.
13  *
14  * @ContentEntityType(
15  *   id = "entity_test_enhanced",
16  *   label = @Translation("Enhanced entity"),
17  *   label_collection = @Translation("Enhanced entities"),
18  *   label_singular = @Translation("enhanced entity"),
19  *   label_plural = @Translation("enhanced entities"),
20  *   label_count = @PluralTranslation(
21  *     singular = "@count enhanced entity",
22  *     plural = "@count enhanced entities",
23  *   ),
24  *   handlers = {
25  *     "storage" = "\Drupal\Core\Entity\Sql\SqlContentEntityStorage",
26  *     "access" = "\Drupal\entity\EntityAccessControlHandler",
27  *     "query_access" = "\Drupal\entity\QueryAccess\QueryAccessHandler",
28  *     "permission_provider" = "\Drupal\entity\EntityPermissionProvider",
29  *     "form" = {
30  *       "add" = "\Drupal\entity\Form\RevisionableContentEntityForm",
31  *       "edit" = "\Drupal\entity\Form\RevisionableContentEntityForm",
32  *       "delete" = "\Drupal\Core\Entity\EntityDeleteForm",
33  *     },
34  *     "route_provider" = {
35  *       "html" = "\Drupal\entity\Routing\DefaultHtmlRouteProvider",
36  *       "revision" = "\Drupal\entity\Routing\RevisionRouteProvider",
37  *       "delete-multiple" = "\Drupal\entity\Routing\DeleteMultipleRouteProvider",
38  *     },
39  *     "local_action_provider" = {
40  *       "collection" = "\Drupal\entity\Menu\EntityCollectionLocalActionProvider",
41  *     },
42  *     "list_builder" = "\Drupal\Core\Entity\EntityListBuilder",
43  *     "views_data" = "\Drupal\views\EntityViewsData",
44  *   },
45  *   base_table = "entity_test_enhanced",
46  *   data_table = "entity_test_enhanced_field_data",
47  *   revision_table = "entity_test_enhanced_revision",
48  *   revision_data_table = "entity_test_enhanced_field_revision",
49  *   translatable = TRUE,
50  *   revisionable = TRUE,
51  *   admin_permission = "administer entity_test_enhanced",
52  *   permission_granularity = "bundle",
53  *   entity_keys = {
54  *     "id" = "id",
55  *     "bundle" = "type",
56  *     "revision" = "vid",
57  *     "langcode" = "langcode",
58  *     "label" = "name",
59  *     "published" = "status",
60  *   },
61  *   links = {
62  *     "add-page" = "/entity_test_enhanced/add",
63  *     "add-form" = "/entity_test_enhanced/add/{type}",
64  *     "edit-form" = "/entity_test_enhanced/{entity_test_enhanced}/edit",
65  *     "canonical" = "/entity_test_enhanced/{entity_test_enhanced}",
66  *     "collection" = "/entity_test_enhanced",
67  *     "delete-multiple-form" = "/entity_test_enhanced/delete",
68  *     "revision" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/view",
69  *     "revision-revert-form" = "/entity_test_enhanced/{entity_test_enhanced}/revisions/{entity_test_enhanced_revision}/revert",
70  *     "version-history" = "/entity_test_enhanced/{entity_test_enhanced}/revisions",
71  *   },
72  * )
73  */
74 class EnhancedEntity extends RevisionableContentEntityBase implements EntityPublishedInterface {
75
76   use EntityPublishedTrait;
77
78   /**
79    * {@inheritdoc}
80    */
81   public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
82     $fields = parent::baseFieldDefinitions($entity_type);
83     $fields += static::publishedBaseFieldDefinitions($entity_type);
84
85     $fields['name'] = BaseFieldDefinition::create('string')
86       ->setLabel('Name')
87       ->setRevisionable(TRUE)
88       ->setDisplayOptions('view', [
89         'label' => 'hidden',
90         'type' => 'string',
91         'weight' => -5,
92       ]);
93
94     return $fields;
95   }
96
97 }