Skip to content

Commit f95b05f

Browse files
authored
Merge pull request #277 from ptt-homme/feature/issue-240-expand-list-of-entity-type-storages
Expand list of entity type storages
2 parents fecdf4c + 65daefa commit f95b05f

File tree

3 files changed

+244
-22
lines changed

3 files changed

+244
-22
lines changed

README.md

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ directory using the `drupal.drupal_root` parameter.
9191

9292
```
9393
parameters:
94-
drupal:
95-
drupal_root: /path/to/drupal
94+
drupal:
95+
drupal_root: /path/to/drupal
9696
```
9797

9898
You can also use container parameters. For instance you can always set it to the current working directory.
9999

100100
```
101101
parameters:
102-
drupal:
103-
drupal_root: %currentWorkingDirectory%
102+
drupal:
103+
drupal_root: %currentWorkingDirectory%
104104
```
105105

106106
### Entity storage mappings.
@@ -111,23 +111,36 @@ default mapping can be found in `extension.neon`. For example:
111111

112112
```
113113
parameters:
114-
drupal:
115-
entityTypeStorageMapping:
116-
node: Drupal\node\NodeStorage
117-
taxonomy_term: Drupal\taxonomy\TermStorage
118-
user: Drupal\user\UserStorage
119-
block: Drupal\Core\Config\Entity\ConfigEntityStorage
114+
drupal:
115+
entityMapping:
116+
block:
117+
class: Drupal\block\Entity\Block
118+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
119+
node:
120+
class: Drupal\node\Entity\Node
121+
storage: Drupal\node\NodeStorage
122+
taxonomy_term:
123+
class: Drupal\taxonomy\Entity\Term
124+
storage: Drupal\taxonomy\TermStorage
125+
user:
126+
class: Drupal\user\Entity\User
127+
storage: Drupal\user\UserStorage
120128
```
121129

122130
To add support for custom entities, you may add the same definition in your project's `phpstan.neon`. See the following
123131
example for adding a mapping for Search API:
124132

125133
```
126134
parameters:
127-
drupal:
128-
entityTypeStorageMapping:
129-
search_api_index: Drupal\search_api\Entity\SearchApiConfigEntityStorage
130-
search_api_server: Drupal\search_api\Entity\SearchApiConfigEntityStorage
135+
drupal:
136+
entityMapping:
137+
block:
138+
search_api_index:
139+
class: Drupal\search_api\Entity\Index
140+
storage: Drupal\search_api\Entity\SearchApiConfigEntityStorage
141+
search_api_server:
142+
class: Drupal\search_api\Entity\Server
143+
storage: Drupal\search_api\Entity\SearchApiConfigEntityStorage
131144
```
132145

133146
Similarly, the `EntityStorageDynamicReturnTypeExtension` service helps to determine the type of the entity which is
@@ -145,11 +158,19 @@ The default mapping can be found in `extension.neon`:
145158
```neon
146159
parameters:
147160
drupal:
148-
entityStorageMapping:
149-
node: Drupal\node\Entity\Node
150-
taxonomy_term: Drupal\taxonomy\Entity\Term
151-
user: Drupal\user\Entity\User
152-
block: Drupal\block\Entity\Block
161+
entityMapping:
162+
block:
163+
class: Drupal\block\Entity\Block
164+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
165+
node:
166+
class: Drupal\node\Entity\Node
167+
storage: Drupal\node\NodeStorage
168+
taxonomy_term:
169+
class: Drupal\taxonomy\Entity\Term
170+
storage: Drupal\taxonomy\TermStorage
171+
user:
172+
class: Drupal\user\Entity\User
173+
storage: Drupal\user\UserStorage
153174
```
154175

155176
To add support for custom entities, you may add the same definition in your project's `phpstan.neon` likewise.

extension.neon

Lines changed: 203 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,218 @@ parameters:
1414
drupal:
1515
drupal_root: '%currentWorkingDirectory%'
1616
entityMapping:
17+
aggregator_feed:
18+
class: Drupal\aggregator\Entity\Feed
19+
storage: Drupal\aggregator\FeedStorage
20+
21+
aggregator_item:
22+
class: Drupal\aggregator\Entity\Item
23+
storage: Drupal\aggregator\ItemStorage
24+
25+
block:
26+
class: Drupal\block\Entity\Block
27+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
28+
29+
block_content:
30+
class: Drupal\block_content\Entity\BlockContent
31+
storage: Drupal\Core\Entity\Sql\SqlContentEntityStorage
32+
33+
block_content_type:
34+
class: Drupal\block_content\Entity\BlockContentType
35+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
36+
37+
comment_type:
38+
class: Drupal\comment\Entity\CommentType
39+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
40+
41+
comment:
42+
class: Drupal\comment\Entity\Comment
43+
storage: Drupal\comment\CommentStorage
44+
45+
contact_form:
46+
class: Drupal\contact\Entity\ContactForm
47+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
48+
49+
contact_message:
50+
class: Drupal\contact\Entity\Message
51+
storage: Drupal\Core\Entity\ContentEntityNullStorage
52+
53+
content_moderation_state:
54+
class: Drupal\content_moderation\Entity\ContentModerationState
55+
storage: Drupal\Core\Entity\Sql\SqlContentEntityStorage
56+
57+
editor:
58+
class: Drupal\editor\Entity\Editor
59+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
60+
61+
field_config:
62+
class: Drupal\field\Entity\FieldConfig
63+
storage: Drupal\field\FieldConfigStorage
64+
65+
field_storage_config:
66+
class: Drupal\field\Entity\FieldStorageConfig
67+
storage: Drupal\field\FieldStorageConfigStorage
68+
69+
file:
70+
class: Drupal\file\Entity\File
71+
storage: Drupal\file\FileStorage
72+
73+
filter_format:
74+
class: Drupal\filter\Entity\FilterFormat
75+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
76+
77+
image_style:
78+
class: Drupal\image\Entity\ImageStyle
79+
storage: Drupal\image\ImageStyleStorage
80+
81+
imce_profile:
82+
class: Drupal\imce\Entity\ImceProfile
83+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
84+
85+
configurable_language:
86+
class: Drupal\language\Entity\ConfigurableLanguage
87+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
88+
89+
language_content_settings:
90+
class: Drupal\language\Entity\ContentLanguageSettings
91+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
92+
93+
media_type:
94+
class: Drupal\media\Entity\MediaType
95+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
96+
97+
media:
98+
class: Drupal\media\Entity\Media
99+
storage: Drupal\media\MediaStorage
100+
101+
menu_link_content:
102+
class: Drupal\menu_link_content\Entity\MenuLinkContent
103+
storage: \Drupal\menu_link_content\MenuLinkContentStorage
104+
105+
metatag_defaults:
106+
class: Drupal\metatag\Entity\MetatagDefaults
107+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
108+
109+
node_type:
110+
class: Drupal\node\Entity\NodeType
111+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
112+
17113
node:
18114
class: Drupal\node\Entity\Node
19115
storage: Drupal\node\NodeStorage
116+
117+
path_alias:
118+
class: Drupal\path_alias\Entity\PathAlias
119+
storage: Drupal\path_alias\PathAliasStorage
120+
121+
rdf_mapping:
122+
class: Drupal\rdf\Entity\RdfMapping
123+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
124+
125+
responsive_image_style:
126+
class: Drupal\responsive_image\Entity\ResponsiveImageStyle
127+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
128+
129+
search_page:
130+
class: Drupal\search\Entity\SearchPage
131+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
132+
133+
search_api_server:
134+
class: Drupal\search_api\Entity\Server
135+
storage: Drupal\search_api\Entity\SearchApiConfigEntityStorage
136+
137+
search_api_index:
138+
class: Drupal\search_api\Entity\Index
139+
storage: Drupal\search_api\Entity\SearchApiConfigEntityStorage
140+
141+
search_api_task:
142+
class: Drupal\search_api\Entity\Task
143+
storage: Drupal\Core\Entity\Sql\SqlContentEntityStorage
144+
145+
shortcut_set:
146+
class: Drupal\shortcut\Entity\ShortcutSet
147+
storage: Drupal\shortcut\ShortcutSetStorage
148+
149+
shortcut:
150+
class: Drupal\shortcut\Entity\Shortcut
151+
storage: Drupal\Core\Entity\Sql\SqlContentEntityStorage
152+
153+
action:
154+
class: Drupal\system\Entity\Action
155+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
156+
157+
menu:
158+
class: Drupal\system\Entity\Menu
159+
storage: Drupal\system\MenuStorage
160+
20161
taxonomy_term:
21162
class: Drupal\taxonomy\Entity\Term
22163
storage: Drupal\taxonomy\TermStorage
164+
165+
taxonomy_vocabulary:
166+
class: Drupal\taxonomy\Entity\Vocabulary
167+
storage: Drupal\taxonomy\VocabularyStorage
168+
169+
tour:
170+
class: Drupal\tour\Entity\Tour
171+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
172+
23173
user:
24174
class: Drupal\user\Entity\User
25175
storage: Drupal\user\UserStorage
26-
block:
27-
class: Drupal\block\Entity\Block
176+
177+
user_role:
178+
class: Drupal\user\Entity\Role
179+
storage: Drupal\user\RoleStorage
180+
181+
webform:
182+
class: Drupal\webform\Entity\Webform
183+
storage: \Drupal\webform\WebformEntityStorage
184+
185+
webform_submission:
186+
class: Drupal\webform\Entity\WebformSubmission
187+
storage: Drupal\webform\WebformSubmissionStorage
188+
189+
webform_options:
190+
class: Drupal\webform\Entity\WebformOptions
191+
storage: \Drupal\webform\WebformOptionsStorage
192+
193+
workflow:
194+
class: Drupal\workflows\Entity\Workflow
195+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
196+
197+
pathauto_pattern:
198+
class: Drupal\pathauto\Entity\PathautoPattern
199+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
200+
201+
view:
202+
class: Drupal\views\Entity\View
203+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
204+
205+
date_format:
206+
class: Drupal\Core\Datetime\Entity\DateFormat
207+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
208+
209+
entity_form_mode:
210+
class: Drupal\Core\Entity\Entity\EntityFormMode
211+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
212+
213+
entity_view_display:
214+
class: Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay
215+
storage: Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage
216+
217+
entity_form_display:
218+
class: Drupal\Core\Entity\Entity\EntityFormDisplay
219+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
220+
221+
entity_view_mode:
222+
class: Drupal\Core\Entity\Entity\EntityViewMode
223+
storage: Drupal\Core\Config\Entity\ConfigEntityStorage
224+
225+
base_field_override:
226+
class: Drupal\Core\Field\Entity\BaseFieldOverride
227+
storage: Drupal\Core\Field\BaseFieldOverrideStorage
228+
28229
parametersSchema:
29230
drupal: structure([
30231
drupal_root: string()

tests/src/Type/data/entity-type-manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
assertType('Drupal\node\NodeStorage', $etm->getStorage('node'));
1111
assertType('Drupal\user\UserStorage', $etm->getStorage('user'));
1212
assertType('Drupal\taxonomy\TermStorage', $etm->getStorage('taxonomy_term'));
13-
assertType('Drupal\Core\Entity\EntityStorageInterface', $etm->getStorage('search_api_index'));
13+
assertType('Drupal\search_api\Entity\SearchApiConfigEntityStorage', $etm->getStorage('search_api_index'));
1414
assertType('Drupal\Core\Config\Entity\ConfigEntityStorage', $etm->getStorage('block'));
1515
assertType('Drupal\Core\Entity\Sql\SqlContentEntityStorage', $etm->getStorage('content_entity_using_default_storage'));
1616
assertType('Drupal\phpstan_fixtures\CustomContentEntityStorage', $etm->getStorage('content_entity_using_custom_storage'));

0 commit comments

Comments
 (0)