Active
Project:
Drupal core
Version:
main
Component:
entity system
Priority:
Normal
Category:
Plan
Assigned:
Unassigned
Reporter:
Created:
18 Apr 2024 at 03:06 UTC
Updated:
15 May 2026 at 13:49 UTC
Jump to comment: Most recent
Currently the majority of the Entity API methods (especially id()) do not strongly indicate their return type and in many cases allow a wider return type than is ever utilized.
We should strength the return type.
This is also required for eventual PHPStan L9 coverage
#3224376: UserInterface::id(), AccountInterface::id() should return int to match typehints
N/A
See child issues
See child issues
See child issues
Comments
Comment #2
jurgenhaasAdding a related issue where the status field value is an integer in the content entity while the same value in the original is a string.
Comment #3
cmlaraOpened #3441689: [META] Stronger Typing for Entity API. The scope is wider than just the Entity subsystem, however it is the root cause of some entity issues. It wont solve existing issues, however it will set a standard for going forward.
Comment #5
casey commentedI added a feature request to #3572543: Introduce EntityInterface::isSame(EntityInterface)
Comment #6
donquixote commentedI can see two scenarios here:
We can cast the value.
To make this possible, we could introduce two traits:
This would be used for most existing entity classes in Drupal core.
This could be used by new entity classes introduced in core or contrib, or for existing entity classes in new major versions of core or contrib.
Another interesting place for this conversion could be in the respective TypedData classes, or in class IntegerItem, which I think are responsible for reading and processing those values. But these classes have always been a mystery to me :)
Comment #7
donquixote commentedI created #3590321: Validate and cast string to integer in IntegerItem and/or IntegerData.
Comment #8
amateescu commentedSee also #3044431: Make Typed Data actually typed :)