Problem/Motivation
The Redirect entity class has no interface of its own: it only implements EntityPublishedInterface. Code that works with redirects, including RedirectRepository's return types, has to type against \Drupal\redirect\Entity\Redirect. Core gives each content entity type its own interface, such as NodeInterface and PathAliasInterface, so other modules can type against it, mock it in unit tests, and swap the entity class with hook_entity_type_alter().
Proposed resolution
Add \Drupal\redirect\RedirectInterface, extending ContentEntityInterface and EntityPublishedInterface, with the entity's public methods: getSource(), setSource(), getSourceUrl(), getSourcePathWithQuery(), getRedirect(), setRedirect(), getRedirectUrl(), getRedirectOptions(), getRedirectOption(), getStatusCode(), setStatusCode(), getCreated(), setCreated(), setLanguage() and getHash(). Redirect implements it, and docblocks such as RedirectRepository's @return tags refer to the interface. Code typed against the class keeps working.
Remaining tasks
- Decide whether the static
generateHash()belongs on the interface. - Add the interface in a merge request.
API changes
A new RedirectInterface, which the Redirect entity implements.
AI disclosure
Generated with the help of an LLM. Claude Code drafted this issue after I found that Redirect has no entity interface while adding a redirect helper to another module. I checked the entity's methods against the 8.x-1.x branch and reviewed the text.
Comments