Commit 80ab8844 authored by katbailey's avatar katbailey

Attempt to deal with registering language-related services to the container

Conflicts:

	core/includes/bootstrap.inc
parent 47c9feb9
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Symfony\Component\ClassLoader\UniversalClassLoader; use Symfony\Component\ClassLoader\UniversalClassLoader;
use Symfony\Component\ClassLoader\ApcUniversalClassLoader; use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
...@@ -2458,7 +2459,15 @@ function drupal_container(ContainerBuilder $reset = NULL) { ...@@ -2458,7 +2459,15 @@ function drupal_container(ContainerBuilder $reset = NULL) {
$container = $reset; $container = $reset;
} }
elseif (!isset($container)) { elseif (!isset($container)) {
// HALP!! // This will only ever happen if an error has been thrown. Just build a new
// ContainerBuilder with only the language_interface and language_content
// services.
$container = new ContainerBuilder();
// An interface language always needs to be available for t() and other
// functions. This default is overridden by drupal_language_initialize()
// during language negotiation.
$container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language');
$container->register(LANGUAGE_TYPE_CONTENT, 'Drupal\\Core\\Language\\Language');
} }
return $container; return $container;
} }
...@@ -2609,31 +2618,11 @@ function get_t() { ...@@ -2609,31 +2618,11 @@ function get_t() {
* @see Drupal\Core\Language\Language * @see Drupal\Core\Language\Language
*/ */
function drupal_language_initialize() { function drupal_language_initialize() {
$types = language_types_get_all();
$container = drupal_container();
// Ensure a language object is registered for each language type, whether the
// site is multilingual or not.
if (language_multilingual()) { if (language_multilingual()) {
include_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach ($types as $type) {
$language = language_types_initialize($type);
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($language));
}
// Allow modules to react on language system initialization in multilingual // Allow modules to react on language system initialization in multilingual
// environments. // environments.
bootstrap_invoke_all('language_init'); bootstrap_invoke_all('language_init');
} }
else {
$default = language_default();
foreach ($types as $type) {
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($default));
}
}
} }
/** /**
......
...@@ -14,13 +14,6 @@ class DrupalBundle extends Bundle ...@@ -14,13 +14,6 @@ class DrupalBundle extends Bundle
public function build(ContainerBuilder $container) public function build(ContainerBuilder $container)
{ {
parent::build($container); parent::build($container);
// An interface language always needs to be available for t() and other
// functions. This default is overridden by drupal_language_initialize()
// during language negotiation.
$container->register(LANGUAGE_TYPE_INTERFACE, 'Drupal\\Core\\Language\\Language');
// Register the default language content.
$container->register(LANGUAGE_TYPE_CONTENT, 'Drupal\\Core\\Language\\Language');
$definitions = array( $definitions = array(
'dispatcher' => array( 'dispatcher' => array(
...@@ -119,6 +112,41 @@ public function build(ContainerBuilder $container) ...@@ -119,6 +112,41 @@ public function build(ContainerBuilder $container)
$container->setDefinition($id, $definition); $container->setDefinition($id, $definition);
} }
// Add language-related services.
$types = language_types_get_all();
// Ensure a language object is registered for each language type, whether the
// site is multilingual or not.
if (language_multilingual()) {
include_once DRUPAL_ROOT . '/core/includes/language.inc';
foreach ($types as $type) {
$language = language_types_initialize($type);
// We cannot pass an object as a parameter to a method on a service.
$info = get_object_vars($language);
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($info));
}
}
else {
$info = variable_get('language_default', array(
'langcode' => 'en',
'name' => 'English',
'direction' => 0,
'weight' => 0,
'locked' => 0,
));
$info['default'] = TRUE;
foreach ($types as $type) {
$container->set($type, NULL);
$container->register($type, 'Drupal\\Core\\Language\\Language')
->addMethodCall('extend', array($info));
}
}
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
} }
} }
\ No newline at end of file
...@@ -44,8 +44,8 @@ public function __construct(array $options = array()) { ...@@ -44,8 +44,8 @@ public function __construct(array $options = array()) {
* *
* @todo Remove this function once $GLOBALS['language'] is gone. * @todo Remove this function once $GLOBALS['language'] is gone.
*/ */
public function extend($obj) { public function extend($info) {
$vars = get_object_vars($obj); $vars = is_array($info) ? $info : get_object_vars($info);
foreach ($vars as $var => $value) { foreach ($vars as $var => $value) {
$this->$var = $value; $this->$var = $value;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment