Repository navigation
Upgrading
This release reports new errors by default, and changes the class name in some existing ones. If your project has a PHPStan baseline, regenerate it after upgrading:
php vendor/bin/phpstan analyse --generate-baselineThe changes behind that:
- Broad entity storages resolve to a different class. See "Entity storage types".
- Field item properties are nullable. See "Field items".
- Render callback methods missing from
trustedCallbacks()are reported. See "Render callbacks". - Translatable categories in
@FieldTypeannotations are reported as deprecated.
Entity storage types
A storage typed with a broad interface, like RevisionableStorageInterface or SqlEntityStorageInterface, resolved to the first entity type in the mapping. That was usually BlockContent or Block, whatever the storage really held. Now it resolves to the base interface every matching entity type shares:
| Caller type | load() returns |
|---|---|
One entity type's storage matches, like NodeStorageInterface |
Node|null, as before |
Content entity storages, like RevisionableStorageInterface, ContentEntityStorageInterface or SqlContentEntityStorage |
ContentEntityInterface|null |
Config entity storages, like ConfigEntityStorageInterface or ConfigEntityStorage |
ConfigEntityInterface|null |
Both kinds, like EntityStorageInterface |
EntityInterface|null |
Errors that named BlockContent, Block, EntityInterface or RevisionableInterface for something loaded from these storages now name ContentEntityInterface or ConfigEntityInterface. That's why baseline entries stop matching:
Ignored error pattern #^Call to an undefined method Drupal\\block\\Entity\\Block\:\:addDisplay\(\)\.$# in path .../ViewStorageTest.php was not matched in reported errors.
Call to an undefined method Drupal\Core\Config\Entity\ConfigEntityInterface::addDisplay().
loadRevision(), loadRevisionUnchanged() and loadMultipleRevisions() now resolve to the entity class too, like load().
Assigning to a content entity field, like $node->title = 'foo', is no longer reported. ContentEntityBase::__set() passes the value to the field's setValue(). After the assignment, $node->title is still a FieldItemListInterface.
Field items
Stored field item properties are nullable, like StringItemBase::$value (?string) and IntegerItem::$value (?int). Items from appendItem() and items on unsaved entities return NULL, and core's isEmpty() methods check for it. Code that passes $item->value to a string parameter is now reported.
New stubs type the properties of TelephoneItem, the options module's list items and ImageItem. ImageItem::$display and $description, and DateRangeItem::$date, are typed null: those classes don't define them, so reading one returns NULL.
Render callbacks
Drupal throws UntrustedCallbackException when a #pre_render, #post_render or #lazy_builder callback is a method that trustedCallbacks() doesn't return. That's now reported:
#pre_render callback method 'preRender' at key '0' is not returned by MyBuilder::trustedCallbacks().
🪪 renderCallback.methodNotInTrustedCallbacks
Container parameters
ContainerInterface::getParameter() returns the type of the parameter's default in the services.yml files, like string for app.root and array for renderer.config. It returned array|bool|float|int|string|UnitEnum|null for every parameter.
Bleeding edge
bleedingEdge.neon enables three new opt-in rules. Each has a drupal.rules.* parameter and a README section.
formApiCallbackRulereports Form API callbacks that fail when Drupal calls them, like a missing function in#validateor a non-static method in[static::class, 'method'].lazyBuilderRulereports#lazy_builderrender arrays that breakRenderer's rules, and arguments that don't match the callback's parameters.phpDocSeeReferenceRulereports@seetags whose class, method or function doesn't exist.
The README no longer says that checkCoreDeprecatedHooksInApiFiles and checkContribDeprecatedHooksInApiFiles report deprecated hooks. They only load the .api.php files. #963 tracks the rule.
Fixes
accessCheck()anywhere in a chained entity query statement marks the query as checked.BrowserTestBase::$defaultThemeset in a trait is found.EntityListBuilderOperationsCacheabilityRuleno longer runs on Drupal 12.0-dev.- An alias that points to a decorator is no longer treated as a second decorator.
What's Changed
- Add TelephoneItem field type stub by @hanming5 in #1073
- Field type deprecated translated category by @stevenspasbo in #788
- Do not treat an alias of a decorator as a decorator by @mglaman in #1084
- Report render callback methods missing from trustedCallbacks() by @mglaman in #1085
- Report Form API callbacks that fail at runtime by @mglaman in #1087
- Report invokable Form API callbacks without __invoke() and static::class . ':method' by @mglaman in #1089
- Report #lazy_builder render arrays that break Renderer's rules by @mglaman in #1090
- Track accessCheck() anywhere in a chained entity query statement by @mglaman in #1091
- Add a regression test for #pre_render callbacks on a union of classes by @mglaman in #1094
- Document that manual installs need rules.neon for loadInclude() files by @mglaman in #1096
- Check #lazy_builder arguments against the callback's parameters by @hanming5 in #1101
- Infer the entity class from loadRevision(), loadRevisionUnchanged() and loadMultipleRevisions() by @mstrelan in #1099
- Infer ContainerInterface::getParameter() types from services.yml files by @hanming5 in #1102
- Skip EntityListBuilderOperationsCacheabilityRule on Drupal 12.0-dev by @mstrelan in #1105
- Make field item stub properties nullable by @hanming5 in #1098
- Find $defaultTheme when a trait sets it by @mglaman in #1108
- Resolve broad entity storages to their base entity interface by @mglaman in #1107
- Say that bleeding edge only loads .api.php files by @mglaman in #1109
- Add options and image field type stubs by @mglaman in #1110
- Type DateRangeItem::$date as null, not never by @mglaman in #1112
- Allow any value to be assigned to a content entity field property by @mstrelan in #1100
- Report @see tags that reference code that doesn't exist by @mglaman in #1113
New Contributors
- @hanming5 made their first contribution in #1073
- @stevenspasbo made their first contribution in #788
Full Changelog: 2.4.0...2.5.0