Download & Extend

Global $language changed to $language_interface

Project: 
Drupal core
Introduced in branch: 
8.x
Description: 

Drupal 6 used to have a $language global to signify *the* page language. In Drupal 7 this was extended to several language types, so $language, $language_content and $language_url are the three built-in language contexts/globals. Drupal 8 is about to introduce a context system (see WSCCI) and the language values need to be namespaced properly to group together. Also, the use of $language as a global made it dangerous to use $language in a local context (eg. inside methods, functions) because the possibility to clash with the global and overwrite the value. There was no $account vs. $user as in Drupal 7.

In Drupal 8 Globals are handled by the dependency injection system. The 'language_manager' service is provide by the CoreBundle and can be used to retrieve a language object of a given type, e.g. LANGUAGE_TYPE_INTERFACE.

Drupal 7:

<?php
global $language;
$output = t('You speak %name', array('%name' => $language->name));
?>

Drupal 8:

<?php
$language
= language(LANGUAGE_TYPE_INTERFACE);
$output = t('You speak %name', array('%name' => $language->name));
?>
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

Docs need to be updated

*edit* never mind, I can see from here that it's already noted that we need to update the docs :)

nobody click here