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_container() is deprecated.
Proposed resolution
Use the Drupal class instead.
Remaining tasks
In the patch I replaced all calls to drupal_container()-get() with Drupal::service(), but I'm not quite sure what to do with the other calls.
I guess we should use Drupal::getContainer() there?
Comment | File | Size | Author |
---|---|---|---|
#14 | bootstrap-2006024-14.patch | 1.32 KB | kgoel |
#11 | bootstrap-2006024-11.patch | 1.91 KB | kgoel |
#11 | interdiff.txt | 776 bytes | kgoel |
#7 | bootstrap-2006024-7.patch | 1.32 KB | kgoel |
#3 | 2006024-drupal_container_bootstrap_php-3.patch | 7.41 KB | rbayliss |
Comments
Comment #1
wesleydv CreditAttribution: wesleydv commentedComment #2
rbayliss CreditAttribution: rbayliss commentedNice, but you should probably use the specific methods on the Drupal object for module handler and key/value.
Drupal::moduleHandler()->...
Drupal::keyValue()->...
Comment #3
rbayliss CreditAttribution: rbayliss commentedReroll with changes from #2, and using Drupal::getContainer() wherever we were needing to return the whole container. It's deprecated, but there's currently no other way.
Comment #4
wesleydv CreditAttribution: wesleydv commentedI believe the question is should: Drupal::getContainer() be deprecated?
If a function is vital for Drupal and there is no other way to do it, it does not seem right to deprecate that function in the first place.
Is using
static::$container;
directly an alternative?Comment #5
ddrozdik CreditAttribution: ddrozdik commentedI will add this task to meta task #2001206: Replace drupal_container() with Drupal::service() as part of same work in other places.
Comment #6
Crell CreditAttribution: Crell commentedDrupal::moduleHandler()
$module_handler = Drupal::moduleHandler();
$module_handler->moduleExists()
// etc.
Using Drupal::getContainer() is very discouraged, but in early bootstrap we sometimes don't have another option. We can leave those in here for the time being. If it can get refactored later, that's for later.
Comment #7
kgoel CreditAttribution: kgoel commentedComment #9
kgoel CreditAttribution: kgoel commented#7: bootstrap-2006024-7.patch queued for re-testing.
Comment #11
kgoel CreditAttribution: kgoel commentedI am not sure why Drupal installation failed. In this patch I have removed deprecated drupal_container function from bootstrap.inc.
Comment #13
Crell CreditAttribution: Crell commentedThere is no such function. I think you mean Drupal::getContainer().
Ibid.
We can't remove this yet. Just stop using it.
Comment #14
kgoel CreditAttribution: kgoel commentedComment #15
Crell CreditAttribution: Crell commentedWhy did this patch shrink so much from #3? Did the rest get committed elsewhere?
Comment #16
kgoel CreditAttribution: kgoel commented@Crell - I am not sure where the rest of the code got committed. I ran grep on drupal_container and found only three instances of it in bootstrap.inc file.
Comment #17
Crell CreditAttribution: Crell commentedhuh. Well, OK, as long as it got done. :-)
Comment #18
Crell CreditAttribution: Crell commented#14: bootstrap-2006024-14.patch queued for re-testing.
Comment #19
catchCommitted/pushed to 8.x, thanks!