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?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wesleydv’s picture

Title: Don't use drupal_container() is deprecated, don't use it in bootstrap.php » drupal_container() is deprecated, don't use it in bootstrap.php
rbayliss’s picture

Nice, but you should probably use the specific methods on the Drupal object for module handler and key/value.

Drupal::moduleHandler()->...
Drupal::keyValue()->...

rbayliss’s picture

Status: Active » Needs review
FileSize
7.41 KB

Reroll 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.

wesleydv’s picture

I 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?

ddrozdik’s picture

I will add this task to meta task #2001206: Replace drupal_container() with Drupal::service() as part of same work in other places.

Crell’s picture

Status: Needs review » Needs work
+++ b/core/includes/bootstrap.inc
@@ -1009,7 +1009,7 @@ function drupal_page_is_cacheable($allow_caching = NULL) {
-  $module_handler = drupal_container()->get('module_handler');
+  $module_handler = Drupal::service('module_handler');

Drupal::moduleHandler()

+++ b/core/includes/bootstrap.inc
@@ -1030,8 +1030,8 @@ function bootstrap_invoke_all($hook) {
-  if ($type == 'module' && drupal_container()->get('module_handler')->moduleExists($name)) {
-    return drupal_container()->get('module_handler')->load($name);
+  if ($type == 'module' && Drupal::service('module_handler')->moduleExists($name)) {
+    return Drupal::service('module_handler')->load($name);

$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.

kgoel’s picture

Status: Needs work » Needs review
FileSize
1.32 KB

Status: Needs review » Needs work

The last submitted patch, bootstrap-2006024-7.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review

#7: bootstrap-2006024-7.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, bootstrap-2006024-7.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
776 bytes
1.91 KB

I am not sure why Drupal installation failed. In this patch I have removed deprecated drupal_container function from bootstrap.inc.

Status: Needs review » Needs work

The last submitted patch, bootstrap-2006024-11.patch, failed testing.

Crell’s picture

+++ b/core/includes/bootstrap.inc
@@ -759,7 +759,7 @@ function drupal_get_filename($type, $name, $filename = NULL) {
+    if (($container = drupal_getContainer()) && $container->has('keyvalue') && function_exists('db_query')) {

There is no such function. I think you mean Drupal::getContainer().

+++ b/core/includes/bootstrap.inc
@@ -2010,9 +2010,9 @@ function _drupal_bootstrap_configuration() {
+  if (!drupal_getContainer()) {

Ibid.

+++ b/core/includes/bootstrap.inc
@@ -2133,20 +2133,6 @@ function drupal_get_bootstrap_phase() {
-function drupal_container() {
-  return Drupal::getContainer();
-}

We can't remove this yet. Just stop using it.

kgoel’s picture

Status: Needs work » Needs review
FileSize
1.32 KB
Crell’s picture

Why did this patch shrink so much from #3? Did the rest get committed elsewhere?

kgoel’s picture

@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.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

huh. Well, OK, as long as it got done. :-)

Crell’s picture

#14: bootstrap-2006024-14.patch queued for re-testing.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.