@@ -5,18 +5,28 @@ declare(strict_types=1);
5
5
namespace Drupal\ {{ machine_name }}\Entity ;
6
6
7
7
{% apply sort_namespaces % }
8
- {% if not revisionable % }
9
- use Drupal\Core\Entity\ContentEntityBase ;
10
- {% endif % }
8
+ use Drupal\Core\Entity\Attribute\ContentEntityType ;
9
+ use Drupal\Core\Entity\ContentEntityDeleteForm ;
10
+ use Drupal\views\EntityViewsData ;
11
+ use Drupal\Core\Entity\Form\DeleteMultipleForm ;
12
+ use Drupal\Core\StringTranslation\TranslatableMarkup ;
13
+ use Drupal\{{ machine_name }}\{{ class }}ListBuilder ;
14
+ use Drupal\{{ machine_name }}\Form\{{ class }}Form ;
11
15
{% if author_base_field % }
12
16
use Drupal\Core\Entity\EntityStorageInterface ;
13
17
{% endif % }
14
18
{% if has_base_fields % }
15
19
use Drupal\Core\Entity\EntityTypeInterface ;
16
20
use Drupal\Core\Field\BaseFieldDefinition ;
21
+ {% endif % }
22
+ {% if not revisionable % }
23
+ use Drupal\Core\Entity\ContentEntityBase ;
17
24
{% endif % }
18
25
{% if revisionable % }
19
26
use Drupal\Core\Entity\RevisionableContentEntityBase ;
27
+ use Drupal\Core\Entity\Form\RevisionDeleteForm ;
28
+ use Drupal\Core\Entity\Form\RevisionRevertForm ;
29
+ use Drupal\Core\Entity\Routing\RevisionHtmlRouteProvider ;
20
30
{% endif % }
21
31
use Drupal\{{ machine_name }}\{{ class }}Interface ;
22
32
{% if author_base_field % }
@@ -25,125 +35,130 @@ use Drupal\user\EntityOwnerTrait;
25
35
{% if changed_base_field % }
26
36
use Drupal\Core\Entity\EntityChangedTrait ;
27
37
{% endif % }
38
+ {% if canonical % }
39
+ use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider ;
40
+ {% else % }
41
+ use Drupal\{{ machine_name }}\Routing\{{ class }}HtmlRouteProvider ;
42
+ {% endif % }
43
+ {% if access_controller % }
44
+ use Drupal\{{ machine_name }}\{{ class }}AccessControlHandler ;
45
+ {% endif % }
28
46
{% endapply % }
29
47
30
48
/**
31
49
* Defines the {{ entity_type_label|lower }} entity class.
32
- *
33
- * @ContentEntityType(
34
- * id = "{{ entity_type_id }}",
35
- * label = @Translation("{{ entity_type_label }}"),
36
- * label_collection = @Translation("{{ entity_type_label|pluralize }}"),
37
- * label_singular = @Translation("{{ entity_type_label|lower }}"),
38
- * label_plural = @Translation("{{ entity_type_label|pluralize|lower }}"),
39
- * label_count = @PluralTranslation(
40
- * singular = "@count {{ entity_type_label|pluralize|lower }}",
41
- * plural = "@count {{ entity_type_label|pluralize|lower }}",
42
- * ),
50
+ */
51
+ # [ContentEntityType(
52
+ id : ' {{ entity_type_id }}' ,
53
+ label : new TranslatableMarkup (' {{ entity_type_label }}' ),
54
+ label_collection : new TranslatableMarkup (' {{ entity_type_label|pluralize }}' ),
55
+ label_singular : new TranslatableMarkup (' {{ entity_type_label|lower }}' ),
56
+ label_plural : new TranslatableMarkup (' {{ entity_type_label|pluralize|lower }}' ),
57
+ entity_keys : [
58
+ ' id' => ' id' ,
59
+ {% if revisionable % }
60
+ ' revision' => ' revision_id' ,
61
+ {% endif % }
62
+ {% if translatable % }
63
+ ' langcode' => ' langcode' ,
64
+ {% endif % }
43
65
{% if bundle % }
44
- * bundle_label = @Translation("{{ entity_type_label }} type") ,
66
+ ' bundle ' => ' bundle ' ,
45
67
{% endif % }
46
- * handlers = {
47
- * "list_builder" = "Drupal\{{ machine_name }}\{{ class }}ListBuilder",
48
- * "views_data" = "Drupal\views\EntityViewsData",
68
+ ' label' => ' {{ label_base_field ? ' label ' : ' id ' }}' ,
69
+ {% if author_base_field % }
70
+ ' owner' => ' uid' ,
71
+ {% endif % }
72
+ ' uuid' => ' uuid' ,
73
+ ],
74
+ handlers : [
75
+ ' list_builder' => {{ class }}ListBuilder :: class ,
76
+ ' views_data' => EntityViewsData :: class ,
49
77
{% if access_controller % }
50
- * " access" = "Drupal\ {{ machine_name }}\{{ class }}AccessControlHandler" ,
78
+ ' access' => {{ class }}AccessControlHandler :: class ,
51
79
{% endif % }
52
- * " form" = {
53
- * " add" = "Drupal\ {{ machine_name }}\Form\{{ class }}Form" ,
54
- * " edit" = "Drupal\ {{ machine_name }}\Form\{{ class }}Form" ,
55
- * " delete" = "Drupal\Core\Entity\ ContentEntityDeleteForm" ,
56
- * " delete-multiple-confirm" = "Drupal\Core\Entity\Form\ DeleteMultipleForm" ,
80
+ ' form' => [
81
+ ' add' => {{ class }}Form :: class ,
82
+ ' edit' => {{ class }}Form :: class ,
83
+ ' delete' => ContentEntityDeleteForm :: class ,
84
+ ' delete-multiple-confirm' => DeleteMultipleForm :: class ,
57
85
{% if revisionable % }
58
- * " revision-delete" = \Drupal\Core\Entity\Form\ RevisionDeleteForm::class,
59
- * " revision-revert" = \Drupal\Core\Entity\Form\ RevisionRevertForm::class,
86
+ ' revision-delete' => RevisionDeleteForm :: class ,
87
+ ' revision-revert' => RevisionRevertForm :: class ,
60
88
{% endif % }
61
- * } ,
62
- * " route_provider" = {
89
+ ] ,
90
+ ' route_provider' => [
63
91
{% if canonical % }
64
- * " html" = "Drupal\Core\Entity\Routing\ AdminHtmlRouteProvider" ,
92
+ ' html' => AdminHtmlRouteProvider :: class ,
65
93
{% else % }
66
- * "html" = "Drupal\{{ machine_name }}\Routing\{{ class }}HtmlRouteProvider",
67
- {% endif %}
68
- {% if revisionable %}
69
- * "revision" = \Drupal\Core\Entity\Routing\RevisionHtmlRouteProvider::class,
70
- {% endif %}
71
- * },
72
- * },
73
- * base_table = "{{ entity_type_id }}",
74
- {% if translatable %}
75
- * data_table = "{{ entity_type_id }}_field_data",
94
+ ' html' => {{ class }}HtmlRouteProvider :: class ,
76
95
{% endif % }
77
96
{% if revisionable % }
78
- * revision_table = "{{ entity_type_id }}_revision",
79
- {% endif %}
80
- {% if revisionable and translatable %}
81
- * revision_data_table = "{{ entity_type_id }}_field_revision",
97
+ ' revision' => RevisionHtmlRouteProvider :: class ,
82
98
{% endif % }
83
- {% if revisionable %}
84
- * show_revision_ui = TRUE,
99
+ ],
100
+ ],
101
+ links : [
102
+ ' collection' => ' /admin/content/{{ entity_type_id_short|u2h }}' ,
103
+ {% if bundle % }
104
+ ' add-form' => ' {{ entity_base_path }}/add/{{ ' {' }}{{ entity_type_id }}{{ ' _type }' }}' ,
105
+ ' add-page' => ' {{ entity_base_path }}/add' ,
106
+ {% else % }
107
+ ' add-form' => ' {{ entity_base_path }}/add' ,
85
108
{% endif % }
86
- {% if translatable %}
87
- * translatable = TRUE,
109
+ ' canonical' => ' {{ entity_base_path }}/{{ ' {' }}{{ entity_type_id }}{{ ' }' }}' ,
110
+ {% if canonical % }
111
+ ' edit-form' => ' {{ entity_base_path }}/{{ ' {' }}{{ entity_type_id }}{{ ' }' }}/edit' ,
112
+ {% else % }
113
+ ' edit-form' => ' {{ entity_base_path }}/{{ ' {' }}{{ entity_type_id }}{{ ' }' }}' ,
88
114
{% endif % }
89
- * admin_permission = "{{ permissions.administer }}",
90
- * entity_keys = {
91
- * "id" = "id",
115
+ ' delete-form' => ' {{ entity_base_path }}/{{ ' {' }}{{ entity_type_id }}{{ ' }' }}/delete' ,
116
+ ' delete-multiple-form' => ' /admin/content/{{ entity_type_id_short|u2h }}/delete-multiple' ,
92
117
{% if revisionable % }
93
- * " revision" = "revision_id" ,
94
- {% endif %}
95
- {% if translatable %}
96
- * "langcode" = "langcode" ,
118
+ ' revision ' => ' {{ entity_base_path }}/{{ ' { ' }}{{ entity_type_id }}{{ ' } ' }}/ revision/{{ ' { ' }}{{ entity_type_id ~ ' _revision ' }}{{ ' } ' }}/view ' ,
119
+ ' revision-delete-form ' => ' {{ entity_base_path }}/{{ ' { ' }}{{ entity_type_id }}{{ ' } ' }}/revision/{{ ' { ' }}{{ entity_type_id ~ ' _revision ' }}{{ ' } ' }}/delete ' ,
120
+ ' revision-revert-form ' => ' {{ entity_base_path }}/{{ ' { ' }}{{ entity_type_id }}{{ ' } ' }}/revision/{{ ' { ' }}{{ entity_type_id ~ ' _revision ' }}{{ ' } ' }}/revert ' ,
121
+ ' version-history ' => ' {{ entity_base_path }}/{{ ' { ' }}{{ entity_type_id }}{{ ' } ' }}/revisions ' ,
97
122
{% endif % }
123
+ ],
124
+ admin_permission : ' {{ permissions.administer }}' ,
98
125
{% if bundle % }
99
- * "bundle" = "bundle",
126
+ bundle_entity_type : ' {{ entity_type_id }}_type' ,
127
+ bundle_label : new TranslatableMarkup (' {{ entity_type_label }} type' ),
100
128
{% endif % }
101
- * "label" = "{{ label_base_field ? 'label' : 'id' }}",
102
- {% if author_base_field %}
103
- * "uuid" = "uuid",
104
- * "owner" = "uid",
105
- {% else %}
106
- * "uuid" = "uuid",
129
+ base_table : ' {{ entity_type_id }}' ,
130
+ {% if translatable % }
131
+ data_table : ' {{ entity_type_id }}_field_data' ,
107
132
{% endif % }
108
- * },
109
133
{% if revisionable % }
110
- * revision_metadata_keys = {
111
- * "revision_user" = "revision_uid",
112
- * "revision_created" = "revision_timestamp",
113
- * "revision_log_message" = "revision_log",
114
- * },
134
+ revision_table : ' {{ entity_type_id }}_revision' ,
115
135
{% endif % }
116
- * links = {
117
- * "collection" = "/admin/content/{{ entity_type_id_short|u2h }}",
118
- {% if bundle %}
119
- * "add-form" = "{{ entity_base_path }}/add/{{ '{' }}{{ entity_type_id }}{{ '_type}' }}",
120
- * "add-page" = "{{ entity_base_path }}/add",
121
- {% else %}
122
- * "add-form" = "{{ entity_base_path }}/add",
136
+ {% if revisionable and translatable % }
137
+ revision_data_table : ' {{ entity_type_id }}_field_revision' ,
123
138
{% endif % }
124
- * "canonical" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}",
125
- {% if canonical %}
126
- * "edit-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/edit",
127
- {% else %}
128
- * "edit-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}",
139
+ {% if translatable % }
140
+ translatable : TRUE ,
129
141
{% endif % }
130
- * "delete-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/delete",
131
- * "delete-multiple-form" = "/admin/content/{{ entity_type_id_short|u2h }}/delete-multiple",
132
142
{% if revisionable % }
133
- * "revision" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/revision/{{ '{' }}{{ entity_type_id ~ '_revision' }}{{ '}' }}/view",
134
- * "revision-delete-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/revision/{{ '{' }}{{ entity_type_id ~ '_revision' }}{{ '}' }}/delete",
135
- * "revision-revert-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/revision/{{ '{' }}{{ entity_type_id ~ '_revision' }}{{ '}' }}/revert",
136
- * "version-history" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/revisions",
143
+ show_revision_ui : TRUE ,
137
144
{% endif % }
138
- * },
145
+ label_count : [
146
+ ' singular' => ' @count {{ entity_type_label|pluralize|lower }}' ,
147
+ ' plural' => ' @count {{ entity_type_label|pluralize|lower }}' ,
148
+ ],
139
149
{% if bundle % }
140
- * bundle_entity_type = "{{ entity_type_id }}_type",
141
- * field_ui_base_route = "entity.{{ entity_type_id }}_type.edit_form",
150
+ field_ui_base_route : ' entity.{{ entity_type_id }}_type.edit_form' ,
142
151
{% elseif fieldable % }
143
- * field_ui_base_route = " entity.{{ entity_type_id }}.settings" ,
152
+ field_ui_base_route : ' entity.{{ entity_type_id }}.settings' ,
144
153
{% endif % }
145
- * )
146
- */
154
+ {% if revisionable % }
155
+ revision_metadata_keys : [
156
+ ' revision_user' => ' revision_uid' ,
157
+ ' revision_created' => ' revision_timestamp' ,
158
+ ' revision_log_message' => ' revision_log' ,
159
+ ],
160
+ {% endif % }
161
+ )]
147
162
final class {{ class }} extends {% if revisionable % }Revisionable {% endif % }ContentEntityBase implements {{ class }}Interface {
148
163
149
164
{% if changed_base_field or author_base_field % }
0 commit comments