Wrong typhing for EntityStorageInterface::loadMultiple()/resetCache()

Created on 17 February 2025, 2 months ago

Problem/Motivation

This issue πŸ“Œ Fix MissingParamType in core/lib/Drupal/Core Needs review added type hints for Drupal\Core\Entity\EntityStorageInterface::loadMultiple() and ::resetCache() as @param int[]|null $ids, which is incorrect.

  • Entity IDs are not guaranteed to be integers; more likely, they will be strings. Even though the base field definition for ID uses an integer DataType by default, it is never cast to an integer and is returned as a string.
  • Drupal\Core\Entity\EntityInterface::id() specifies return types as @return string|int|null, which already makes a simple use of ::loadMultiple([$node->id()]) completely incorrect.
  • Drupal\Core\Config\Entity\ConfigEntityStorageInterface extends this interface, making it problematic as well, because in general, Drupal configurations use strings as their IDs, not integers.
  • It is a generic interface for all kinds of different entity types and subtypes, and it shouldn't enforce such strict types, as even the Drupal core ones are already incompatible with it.

Proposed resolution

Add an array of strings to the type hint as well, since it is a valid argument.

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

other

Created by

πŸ‡·πŸ‡ΊRussia niklan Russia, Perm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024