Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
\Drupal::getContainer()
can only return a new \Symfony\Component\DependencyInjection\ContainerInterface
or throw a new \Drupal\Core\DependencyInjection\ContainerNotInitializedException
. The type hint incorrectly notes that a NULL
could potentially be returned.
Proposed resolution
Update the type hint to remove |null
.
Remaining tasks
Task | Novice task? | Contributor instructions | Complete? |
---|---|---|---|
Create a patch | Yes | Instructions | Yes |
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | No | Instructions |
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
- Resolved an incorrect type hint on \Drupal::getContainer().
Comment | File | Size | Author |
---|---|---|---|
#2 | fix-getcontainer-typehint-3061564-1.patch | 513 bytes | cyb_tachyon |
Comments
Comment #2
cyb_tachyon CreditAttribution: cyb_tachyon at Red Hat commentedAdding patch. Ready for review.
Comment #3
shreyal999 CreditAttribution: shreyal999 at Srijan | A Material+ Company commentedThe Above patch looks good, can move it further as the return is now just ContainerInterface.
Comment #4
borisson_Not sure what else actually needs to be done on this.
Comment #5
alexpottCommitted and pushed e56e16e156 to 8.8.x and f1a175f4d6 to 8.7.x. Thanks!
Backported to 8.7.x as this is a docs fix.