Conversation
… as nullable The $cacheability parameter in hook_entity_operation and hook_entity_operation_alter is not nullable — only EntityListBuilder methods use nullable for BC purposes (removed in D12). The previous rules passed isNullable=true, rejecting non-nullable CacheableMetadata and suggesting the wrong ?CacheableMetadata $cacheability = NULL form. Fixes #984 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the hook entity operation cacheability rules to accept the canonical non-nullable CacheableMetadata $cacheability parameter (while keeping nullable forms accepted) and aligns test fixtures/error messages with that recommendation.
Changes:
- Adjusted both procedural and attribute-based hook rules to accept non-nullable
CacheableMetadataparameters. - Updated rule error messages to recommend the non-nullable canonical signature.
- Expanded test fixtures to include “good” non-nullable examples and updated PHPUnit expectations accordingly.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/Rules/Drupal/ProceduralHookEntityOperationCacheabilityRule.php |
Accepts non-nullable CacheableMetadata parameter for procedural hook signatures and updates guidance message. |
src/Rules/Drupal/HookEntityOperationCacheabilityRule.php |
Accepts non-nullable CacheableMetadata parameter for #[Hook(...)] methods and updates guidance message. |
tests/src/Rules/ProceduralHookEntityOperationCacheabilityRuleTest.php |
Updates expected error messages to recommend non-nullable signature. |
tests/src/Rules/HookEntityOperationCacheabilityRuleTest.php |
Updates expected error messages to recommend non-nullable signature. |
tests/src/Rules/data/mymodule.module |
Adds “good” examples for procedural hooks (but currently not actually validated as hooks by the procedural rule). |
tests/src/Rules/data/hook-entity-operation-cacheability.php |
Adds “good” non-nullable and nullable OOP hook implementations for fixture coverage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$cacheabilityinhook_entity_operationandhook_entity_operation_alteris not nullable — onlyEntityListBuildermethods use nullable for BC (removed in D12)isValidParam(..., true, ...)→falsein both hook rules so non-nullableCacheableMetadata $cacheabilityis accepted (nullable is also still accepted)\Drupal\Core\Cache\CacheableMetadata $cacheabilitywithout?/= NULLTest plan
php vendor/bin/phpunit --filter=HookEntityOperationCacheabilityRuleTestphp vendor/bin/phpunit --filter=ProceduralHookEntityOperationCacheabilityRuleTestphp vendor/bin/phpunit --filter=EntityListBuilderOperationsCacheabilityRuleTest(unchanged, still nullable)php vendor/bin/phpcs src/🤖 Generated with Claude Code