@@ -5,18 +5,28 @@ declare(strict_types=1);
55namespace Drupal\ {{ machine_name }}\Entity ;
66
77{% 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 ;
1115 {% if author_base_field % }
1216use Drupal\Core\Entity\EntityStorageInterface ;
1317 {% endif % }
1418 {% if has_base_fields % }
1519use Drupal\Core\Entity\EntityTypeInterface ;
1620use Drupal\Core\Field\BaseFieldDefinition ;
21+ {% endif % }
22+ {% if not revisionable % }
23+ use Drupal\Core\Entity\ContentEntityBase ;
1724 {% endif % }
1825 {% if revisionable % }
1926use 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 ;
2030 {% endif % }
2131use Drupal\{{ machine_name }}\{{ class }}Interface ;
2232 {% if author_base_field % }
@@ -25,125 +35,130 @@ use Drupal\user\EntityOwnerTrait;
2535 {% if changed_base_field % }
2636use Drupal\Core\Entity\EntityChangedTrait ;
2737 {% 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 % }
2846{% endapply % }
2947
3048/**
3149 * 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 % }
4365{% if bundle % }
44- * bundle_label = @Translation("{{ entity_type_label }} type") ,
66+ ' bundle ' => ' bundle ' ,
4567{% 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 ,
4977{% if access_controller % }
50- * " access" = "Drupal\ {{ machine_name }}\{{ class }}AccessControlHandler" ,
78+ ' access' => {{ class }}AccessControlHandler :: class ,
5179{% 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 ,
5785{% 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 ,
6088{% endif % }
61- * } ,
62- * " route_provider" = {
89+ ] ,
90+ ' route_provider' => [
6391{% if canonical % }
64- * " html" = "Drupal\Core\Entity\Routing\ AdminHtmlRouteProvider" ,
92+ ' html' => AdminHtmlRouteProvider :: class ,
6593{% 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 ,
7695{% endif % }
7796{% 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 ,
8298{% 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' ,
85108{% 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 }}{{ ' }' }}' ,
88114{% 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' ,
92117{% 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 ' ,
97122{% endif % }
123+ ],
124+ admin_permission : ' {{ permissions.administer }}' ,
98125{% if bundle % }
99- * "bundle" = "bundle",
126+ bundle_entity_type : ' {{ entity_type_id }}_type' ,
127+ bundle_label : new TranslatableMarkup (' {{ entity_type_label }} type' ),
100128{% 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' ,
107132{% endif % }
108- * },
109133{% 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' ,
115135{% 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' ,
123138{% 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 ,
129141{% endif % }
130- * "delete-form" = "{{ entity_base_path }}/{{ '{' }}{{ entity_type_id }}{{ '}' }}/delete",
131- * "delete-multiple-form" = "/admin/content/{{ entity_type_id_short|u2h }}/delete-multiple",
132142{% 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 ,
137144{% endif % }
138- * },
145+ label_count : [
146+ ' singular' => ' @count {{ entity_type_label|pluralize|lower }}' ,
147+ ' plural' => ' @count {{ entity_type_label|pluralize|lower }}' ,
148+ ],
139149{% 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' ,
142151{% elseif fieldable % }
143- * field_ui_base_route = " entity.{{ entity_type_id }}.settings" ,
152+ field_ui_base_route : ' entity.{{ entity_type_id }}.settings' ,
144153{% 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+ )]
147162final class {{ class }} extends {% if revisionable % }Revisionable {% endif % }ContentEntityBase implements {{ class }}Interface {
148163
149164{% if changed_base_field or author_base_field % }
0 commit comments