<code>
-    global $language_interface;
+    $language_interface = drupal_container()->get(LANGUAGE_TYPE_INTERFACE);

This seems unnecessarily verbose. For lock/queue etc. moving to the container we've left in global procedural wrappers which just call drupal_container() so there's a convenient way to access it. What about something like that for language? Or is there a way to make the drupal_container() call itself a bit prettier?

If everything is injected we don't have this problem, but I don't see that completely going away during this release cycle so it'd be good to have even an interim solution.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RobLoach’s picture

We were playing with the idea of a drupal($service) function that would retrieve the desired service.

  function drupal($service) {
    return drupal_container()->get($service);
  }

  $language_interface = drupal(LANGUAGE_TYPE_INTERFACE);

But, in the end, a wrapper function is just a wrapper function. It doesn't actually help you architecturally. For that reason, we've been focusing on getting the objects in there first, and worrying about minuet micro-syntax-optimizations like that later. We don't want to be STUPID ;-) .

Regarding the language system, the end goal is to move drupal_language_initialize() to a LanguageSystem class, and a "language" service. This means that there would not be a language bootstrap as the entire language system would be lazy-loaded the first time you try to use it. I believe that's at #1550866: Remove obsolete drupal_language_initialize().

catch’s picture

drupal($service) could be fun. Yeah there's no architectural benefit here, but it's also no fun walking around a building site to get into a nicely architected building either ;)

alexweber’s picture

Berdir’s picture

Title: Getting a language out of drupal_container() is very verbose » Replace language() with Drupal::language().

Wow, that's an old issue ;)

This changed a lot already, we have the language() function now, which we should move to the Drupal class as it's a "service-exposing" function.

Cameron Tod’s picture

Status: Active » Needs review
FileSize
57.13 KB

Getting weird test errors here that are a bit beyond me. Let's see how this goes with the testbot while I continue to hack away.

Status: Needs review » Needs work

The last submitted patch, 1630050-replace_language_drupal_language.patch, failed testing.

Cameron Tod’s picture

Status: Needs work » Needs review
FileSize
57.14 KB

Woops, missing a namespacing.

Status: Needs review » Needs work

The last submitted patch, 1630050-replace_language_drupal_language-7.patch, failed testing.

Berdir’s picture

+++ b/core/lib/Drupal/Core/Condition/ConditionManager.phpundefined
@@ -33,7 +33,7 @@ public function __construct(\Traversable $namespaces) {
-    $this->discovery = new CacheDecorator($this->discovery, 'condition:' . language(Language::TYPE_INTERFACE)->langcode);
+    $this->discovery = new CacheDecorator($this->discovery, 'condition:' . Drupal::language(Language::TYPE_INTERFACE)->langcode);

You need to use \Drupal in classes.

Cameron Tod’s picture

Status: Needs work » Needs review
FileSize
57.22 KB

Thanks ack - hopefully I got them all.

Status: Needs review » Needs work

The last submitted patch, 1630050-replace_language_drupal_language-10.patch, failed testing.

Cameron Tod’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1630050-replace_language_drupal_language-10.patch, failed testing.

RobLoach’s picture

Status: Needs work » Needs review
FileSize
57.83 KB
+++ b/core/lib/Drupal.phpundefined
@@ -195,6 +195,26 @@ public static function keyValueExpirable($collection) {
+  public static function language($type) {
+    if (!static::$container->has('language_manager')) {
+      // This happens in rare situations when the container has not been built by
+      // a kernel and has no services, e.g., when t() is called during unit tests
+      // for assertions.
+      static::$container->register('language_manager', 'Drupal\Core\Language\LanguageManager');
+    }
+    return static::$container->get('language_manager')->getLanguage($type);

We might be able to move the service registration into the CoreBundle. There might be instances where we can't do this though. Let's see what the test bot says.

Status: Needs review » Needs work

The last submitted patch, 1630050.patch, failed testing.

Cameron Tod’s picture

Status: Needs work » Needs review

#14: 1630050.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1630050.patch, failed testing.

Cameron Tod’s picture

Status: Needs work » Needs review
Berdir’s picture

#14: 1630050.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1630050.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updating summary.

Berdir’s picture

Issue summary: View changes
Status: Needs work » Closed (duplicate)

language() is gone, closing.