Skip to content

Commit 2627c14

Browse files
committed
Add documentation for contrib entity mapping
Fixes #281
1 parent 00ac45e commit 2627c14

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,43 @@ parameters:
174174
```
175175

176176
To add support for custom entities, you may add the same definition in your project's `phpstan.neon` likewise.
177+
178+
### Providing entity type mappings for a contrib module
179+
180+
Contributed modules can provide their own mapping that can be automatically registered with a user's code base when
181+
they use the `phpstan/extension-installer`. The extension installer scans installed package's `composer.json` for a
182+
value in `extra.phpstan`. This will automatically bundle the defined include that contains an entity mapping
183+
configuration.
184+
185+
For example, the Paragraphs module could have the following `entity_mapping.neon` file:
186+
187+
```neon
188+
parameters:
189+
entityMapping:
190+
paragraph:
191+
class: Drupal\paragraphs\Entity\Paragraph
192+
paragraphs_type:
193+
class: Drupal\paragraphs\Entity\ParagraphsType
194+
```
195+
196+
Then in the `composer.json` for Paragraphs, the `entity_mapping.neon` would be provided as a PHPStan include
197+
198+
```json
199+
{
200+
"name": "drupal/paragraphs",
201+
"description": "Enables the creation of Paragraphs entities.",
202+
"type": "drupal-module",
203+
"license": "GPL-2.0-or-later",
204+
"require": {
205+
"drupal/entity_reference_revisions": "~1.3"
206+
},
207+
"extra": {
208+
"phpstan": {
209+
"includes": [
210+
"entity_mapping.neon"
211+
]
212+
}
213+
}
214+
}
215+
216+
```

0 commit comments

Comments
 (0)