Commit c34c3dfd authored by alexpott's avatar alexpott

Issue #2225427 by ianthomas_uk, martin107, JeroenT, LoMo: Remove remaining...

Issue #2225427 by ianthomas_uk, martin107, JeroenT, LoMo: Remove remaining uses of deprecated language functions (mostly in object oriented code)
parent f8aa6c2e
......@@ -10,7 +10,7 @@
/**
* An object containing the information for an interface language.
*
* @see language_default()
* @see \Drupal\Core\Language\LanguageManager::getLanguage()
*/
class Language implements LanguageInterface {
......
......@@ -31,10 +31,11 @@ interface MailManagerInterface extends PluginManagerInterface {
* user_preferred_langcode(). If you send email based on form values filled on
* the page, there are two additional choices if you are not sending the email
* to a user on the site. You can either use the language used to generate the
* page or the site default language. See language_default(). The former is
* good if sending email to the person filling the form, the later is good if
* you send email to an address previously set up (like contact addresses in a
* contact form).
* page or the site default language. See
* Drupal\Core\Language\LanguageManagerInterface::getDefaultLanguage(). The
* former is good if sending email to the person filling the form, the later
* is good if you send email to an address previously set up (like contact
* addresses in a contact form).
*
* Taking care of always using the proper language is even more important when
* sending emails in a row to multiple users. Hook_mail() abstracts whether
......
......@@ -188,7 +188,7 @@ function getPreferredLangcode($fallback_to_default = TRUE) {
return $language_list[$this->preferred_langcode]->getId();
}
else {
return $fallback_to_default ? language_default()->getId() : '';
return $fallback_to_default ? \Drupal::languageManager()->getDefaultLanguage()->getId() : '';
}
}
......@@ -201,7 +201,7 @@ function getPreferredAdminLangcode($fallback_to_default = TRUE) {
return $language_list[$this->preferred_admin_langcode]->getId();
}
else {
return $fallback_to_default ? language_default()->getId() : '';
return $fallback_to_default ? \Drupal::languageManager()->getDefaultLanguage()->getId() : '';
}
}
......
......@@ -43,7 +43,7 @@ class Language extends TypedData {
*/
public function getValue() {
if (!isset($this->language) && $this->id) {
$this->language = language_load($this->id);
$this->language = \Drupal::languageManager()->getLanguage($this->id);
}
return $this->language;
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Action\ConfigurableActionBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Mail\MailManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
......@@ -57,6 +58,12 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
*/
protected $mailManager;
/** The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a EmailAction object.
*
......@@ -74,14 +81,17 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug
* A logger instance.
* @param \Drupal\Core\Mail\MailManagerInterface
* The mail manager.
* @param \Drupal\Core\Language\LanguageManagerInterface
* The language manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger, MailManagerInterface $mail_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, EntityManagerInterface $entity_manager, LoggerInterface $logger, MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
$this->storage = $entity_manager->getStorage('user');
$this->logger = $logger;
$this->mailManager = $mail_manager;
$this->languageManager = $language_manager;
}
/**
......@@ -92,7 +102,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('token'),
$container->get('entity.manager'),
$container->get('logger.factory')->get('action'),
$container->get('plugin.manager.mail')
$container->get('plugin.manager.mail'),
$container->get('language_manager')
);
}
......@@ -115,7 +126,7 @@ public function execute($entity = NULL) {
$langcode = $recipient_account->getPreferredLangcode();
}
else {
$langcode = language_default()->getId();
$langcode = $this->languageManager->getDefaultLanguage()->getId();
}
$params = array('context' => $this->configuration);
......
......@@ -110,7 +110,7 @@ function comment_tokens($type, $tokens, array $data = array(), array $options =
$url_options = array('absolute' => TRUE);
if (isset($options['langcode'])) {
$url_options['language'] = language_load($options['langcode']);
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
$langcode = $options['langcode'];
}
else {
......
......@@ -39,7 +39,7 @@ function testConfigLanguageOverride() {
// The language module implements a config factory override object that
// overrides configuration when the Language module is enabled. This test ensures that
// English overrides work.
\Drupal::languageManager()->setConfigOverrideLanguage(language_load('en'));
\Drupal::languageManager()->setConfigOverrideLanguage(\Drupal::languageManager()->getLanguage('en'));
$config = \Drupal::config('config_test.system');
$this->assertIdentical($config->get('foo'), 'en bar');
......@@ -50,11 +50,11 @@ function testConfigLanguageOverride() {
ConfigurableLanguage::createFromLangcode('fr')->save();
ConfigurableLanguage::createFromLangcode('de')->save();
\Drupal::languageManager()->setConfigOverrideLanguage(language_load('fr'));
\Drupal::languageManager()->setConfigOverrideLanguage(\Drupal::languageManager()->getLanguage('fr'));
$config = \Drupal::config('config_test.system');
$this->assertIdentical($config->get('foo'), 'fr bar');
\Drupal::languageManager()->setConfigOverrideLanguage(language_load('de'));
\Drupal::languageManager()->setConfigOverrideLanguage(\Drupal::languageManager()->getLanguage('de'));
$config = \Drupal::config('config_test.system');
$this->assertIdentical($config->get('foo'), 'de bar');
......@@ -94,7 +94,7 @@ function testConfigLanguageOverride() {
$this->assertIdentical($config->get('value'), array('key' => 'override'));
// Ensure renaming the config will rename the override.
\Drupal::languageManager()->setConfigOverrideLanguage(language_load('en'));
\Drupal::languageManager()->setConfigOverrideLanguage(\Drupal::languageManager()->getLanguage('en'));
\Drupal::configFactory()->rename('config_test.foo', 'config_test.bar');
$config = \Drupal::config('config_test.bar');
$this->assertEqual($config->get('value'), array('key' => 'original'));
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
......@@ -76,9 +77,11 @@ class ConfigEntityMapper extends ConfigNamesMapper {
* The string translation manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager, EntityManagerInterface $entity_manager) {
parent::__construct($plugin_id, $plugin_definition, $config_factory, $typed_config, $locale_config_manager, $config_mapper_manager, $route_provider, $translation_manager);
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
parent::__construct($plugin_id, $plugin_definition, $config_factory, $typed_config, $locale_config_manager, $config_mapper_manager, $route_provider, $translation_manager, $language_manager);
$this->setType($plugin_definition['entity_type']);
$this->entityManager = $entity_manager;
......@@ -99,7 +102,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('plugin.manager.config_translation.mapper'),
$container->get('router.route_provider'),
$container->get('string_translation'),
$container->get('entity.manager')
$container->get('entity.manager'),
$container->get('language_manager')
);
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
......@@ -83,6 +84,13 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
*/
protected $langcode = NULL;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a ConfigNamesMapper.
*
......@@ -110,12 +118,14 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* The route provider.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*
* @throws \Symfony\Component\Routing\Exception\RouteNotFoundException
* Throws an exception if the route specified by the 'base_route_name' in
* the plugin definition could not be found by the route provider.
*/
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $string_translation) {
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $string_translation, LanguageManagerInterface $language_manager) {
$this->pluginId = $plugin_id;
$this->pluginDefinition = $plugin_definition;
$this->routeProvider = $route_provider;
......@@ -126,6 +136,7 @@ public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterfa
$this->configMapperManager = $config_mapper_manager;
$this->stringTranslation = $string_translation;
$this->languageManager = $language_manager;
}
/**
......@@ -142,7 +153,8 @@ public static function create(ContainerInterface $container, array $configuratio
$container->get('locale.config.typed'),
$container->get('plugin.manager.config_translation.mapper'),
$container->get('router.route_provider'),
$container->get('string_translation')
$container->get('string_translation'),
$container->get('language_manager')
);
}
......@@ -400,7 +412,7 @@ public function getLangcode() {
*/
public function getLanguageWithFallback() {
$langcode = $this->getLangcode();
$language = language_load($langcode);
$language = $this->languageManager->getLanguage($langcode);
// If the language of the file is English but English is not a configured
// language on the site, create a mock language object to represent this
// language run-time. In this case, the title of the language is
......
......@@ -121,7 +121,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $
$mapper = $this->configMapperManager->createInstance($plugin_id);
$mapper->populateFromRequest($request);
$language = language_load($langcode);
$language = $this->languageManager->getLanguage($langcode);
if (!$language) {
throw new NotFoundHttpException();
}
......
......@@ -136,7 +136,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $
$mapper = $this->configMapperManager->createInstance($plugin_id);
$mapper->populateFromRequest($request);
$language = language_load($langcode);
$language = $this->languageManager->getLanguage($langcode);
if (!$language) {
throw new NotFoundHttpException();
}
......
......@@ -348,7 +348,7 @@ public function testContactConfigEntityTranslation() {
// Test that delete links work and operations perform properly.
foreach ($this->langcodes as $langcode) {
$replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => language_load($langcode)->getName());
$replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => \Drupal::languageManager()->getLanguage($langcode)->getName());
$this->drupalGet("$translation_base_url/$langcode/delete");
$this->assertRaw(t('Are you sure you want to delete the @language translation of %label?', $replacements));
......
......@@ -47,6 +47,13 @@ class ConfigEntityMapperTest extends UnitTestCase {
*/
protected $routeProvider;
/**
* The mocked language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface $language_manager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $languageManager;
protected function setUp() {
$this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
......@@ -75,6 +82,8 @@ protected function setUp() {
->disableOriginalConstructor()
->getMock();
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$this->configEntityMapper = new ConfigEntityMapper(
'configurable_language',
$definition,
......@@ -84,7 +93,8 @@ protected function setUp() {
$this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
$this->routeProvider,
$this->getStringTranslationStub(),
$this->entityManager
$this->entityManager,
$this->languageManager
);
}
......
......@@ -81,6 +81,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
protected $urlGenerator;
/**
* The mocked language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface $language_manager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $languageManager;
protected function setUp() {
$this->routeProvider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
......@@ -113,6 +120,8 @@ protected function setUp() {
->with('system.site_information_settings')
->will($this->returnValue($this->baseRoute));
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$this->configNamesMapper = new TestConfigNamesMapper(
'system.site_information_settings',
$this->pluginDefinition,
......@@ -121,7 +130,8 @@ protected function setUp() {
$this->localeConfigManager,
$this->configMapperManager,
$this->routeProvider,
$this->getStringTranslationStub()
$this->getStringTranslationStub(),
$this->languageManager
);
}
......
......@@ -91,7 +91,7 @@ function contact_mail($key, &$message, $params) {
$contact_message = $params['contact_message'];
/** @var $sender \Drupal\user\UserInterface */
$sender = $params['sender'];
$language = language_load($message['langcode']);
$language = \Drupal::languageManager()->getLanguage($message['langcode']);
$variables = array(
'!site-name' => \Drupal::config('system.site')->get('name'),
......
......@@ -65,7 +65,7 @@ class ContentTranslationContextualLinksTest extends WebTestBase {
protected function setUp() {
parent::setUp();
// Set up an additional language.
$this->langcodes = array(language_default()->getId(), 'es');
$this->langcodes = array(\Drupal::languageManager()->getDefaultLanguage()->getId(), 'es');
ConfigurableLanguage::createFromLangcode('es')->save();
// Create a content type.
......
......@@ -929,7 +929,7 @@ function file_tokens($type, $tokens, array $data = array(), array $options = arr
$url_options = array('absolute' => TRUE);
if (isset($options['langcode'])) {
$url_options['language'] = language_load($options['langcode']);
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
$langcode = $options['langcode'];
}
else {
......
......@@ -117,7 +117,7 @@ public function validateCustom(array $form, FormStateInterface $form_state) {
// Reuse the editing form validation routine if we add a custom language.
$this->validateCommon($form['custom_language'], $form_state);
if ($language = language_load($langcode)) {
if ($language = $this->languageManager->getLanguage($langcode)) {
$form_state->setErrorByName('langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode)));
}
}
......@@ -135,7 +135,7 @@ public function validatePredefined($form, FormStateInterface $form_state) {
$form_state->setErrorByName('predefined_langcode', $this->t('Fill in the language details and save the language with <em>Add custom language</em>.'));
}
else {
if ($language = language_load($langcode)) {
if ($language = $this->languageManager->getLanguage($langcode)) {
$form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode)));
}
}
......
......@@ -101,7 +101,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$langcode = $this->entity->id();
// Warn and redirect user when attempting to delete the default language.
if (language_default()->getId() == $langcode) {
if ($this->languageManager->getDefaultLanguage()->getId() == $langcode) {
drupal_set_message($this->t('The default language cannot be deleted.'));
$url = $this->urlGenerator->generateFromPath('admin/config/regional/language', array('absolute' => TRUE));
return new RedirectResponse($url);
......
......@@ -9,7 +9,11 @@
use Drupal\Core\Config\Entity\DraggableListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a class to build a listing of language entities.
......@@ -23,6 +27,39 @@ class LanguageListBuilder extends DraggableListBuilder {
*/
protected $entitiesKey = 'languages';
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('language_manager')
);
}
/**
* Constructs a new EntityListController object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage controller class.
* @param \Drupal\Core\Language\LanguageManagerInterface
* The language manager.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, LanguageManagerInterface $language_manager) {
parent::__construct($entity_type, $storage);
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
......@@ -47,7 +84,7 @@ public function getFormId() {
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$default = language_default();
$default = $this->languageManager->getDefaultLanguage();
// Deleting the site default language is not allowed.
if ($entity->id() == $default->getId()) {
......@@ -89,10 +126,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$language_manager = \Drupal::languageManager();
$language_manager->reset();
if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
$language_manager->updateLockedLanguageWeights();
$this->languageManager->reset();
if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
$this->languageManager->updateLockedLanguageWeights();
}
drupal_set_message(t('Configuration saved.'));
......
......@@ -117,7 +117,7 @@ public function get($name) {
$data_definition = $this->typedConfigManager->buildDataDefinition($definition, $data);
// Unless the configuration has a explicit language code we assume English.
$langcode = isset($default['langcode']) ? $default['langcode'] : 'en';
$wrapper = new LocaleTypedConfig($data_definition, $name, $langcode, $this, $this->typedConfigManager);
$wrapper = new LocaleTypedConfig($data_definition, $name, $langcode, $this, $this->typedConfigManager, $this->languageManager);
$wrapper->setValue($data);
return $wrapper;
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\locale;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\TypedData\ContextAwareInterface;
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\Config\Schema\Element;
......@@ -47,6 +48,13 @@ class LocaleTypedConfig extends Element {
*/
protected $typedConfigManager;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a configuration wrapper object.
*
......@@ -60,12 +68,15 @@ class LocaleTypedConfig extends Element {
* The locale configuration manager object.
* @param \Drupal\locale\TypedConfigManagerInterface $typed_config;
* The typed configuration manager interface.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(DataDefinitionInterface $definition, $name, $langcode, LocaleConfigManager $locale_config, TypedConfigManagerInterface $typed_config) {
public function __construct(DataDefinitionInterface $definition, $name, $langcode, LocaleConfigManager $locale_config, TypedConfigManagerInterface $typed_config, LanguageManagerInterface $language_manager) {
parent::__construct($definition, $name);
$this->langcode = $langcode;
$this->localeConfig = $locale_config;
$this->typedConfigManager = $typed_config;
$this->languageManager = $language_manager;
}
/**
......@@ -91,7 +102,7 @@ public function getTranslation($langcode) {
* {@inheritdoc}
*/
public function language() {
return language_load($this->langcode);
return $this->languageManager->getLanguage($this->langcode);
}
/**
......
......@@ -5,7 +5,7 @@ services:
- { name: event_subscriber }
node.grant_storage:
class: Drupal\node\NodeGrantDatabaseStorage
arguments: ['@database', '@module_handler']
arguments: ['@database', '@module_handler', '@language_manager']
tags:
- { name: backend_overridable }
access_check.node.revision:
......
......@@ -13,6 +13,7 @@
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\User;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -38,6 +39,13 @@ class NodeGrantDatabaseStorage implements NodeGrantDatabaseStorageInterface {
*/
protected $moduleHandler;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a NodeGrantDatabaseStorage object.
*
......@@ -45,10 +53,13 @@ class NodeGrantDatabaseStorage implements NodeGrantDatabaseStorageInterface {
* The database connection.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(Connection $database, ModuleHandlerInterface $module_handler) {
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) {
$this->database = $database;
$this->moduleHandler = $module_handler;
$this->languageManager = $language_manager;
}
/**
......@@ -201,7 +212,7 @@ public function write(NodeInterface $node, array $grants, $realm = NULL, $delete
continue;
}
if (isset($grant['langcode'])) {
$grant_languages = array($grant['langcode'] => language_load($grant['langcode']));
$grant_languages = array($grant['langcode'] => $this->languageManager->getLanguage($grant['langcode']));
}
else {
$grant_languages = $node->getTranslationLanguages(TRUE);
......
......@@ -18,6 +18,7 @@
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessibleInterface;
use Drupal\Core\Database\Query\Condition;
......@@ -65,6 +66,13 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter
*/
protected $searchSettings;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The Drupal account to use for checking for access to advanced search.
*
......@@ -111,6 +119,7 @@ static public function create(ContainerInterface $container, array $configuratio
$container->get('entity.manager'),
$container->get('module_handler'),
$container->get('config.factory')->get('search.settings'),
$container->get('language_manager'),
$container->get('current_user')
);
}
......@@ -132,14 +141,17 @@ static public function create(ContainerInterface $container, array $configuratio
* A module manager object.
* @param \Drupal\Core\Config\Config $search_settings
* A config object for 'search.settings'.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Session\AccountInterface $account
* The $account object to use for checking for access to advanced search.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, AccountInterface $account = NULL) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, Connection $database, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, Config $search_settings, LanguageManagerInterface $language_manager, AccountInterface $account = NULL) {
$this->database = $database;
$this->entityManager = $entity_manager;
$this->moduleHandler = $module_handler;
$this->searchSettings = $search_settings;
$this->languageManager = $language_manager;
$this->account = $account;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
......@@ -302,7 +314,7 @@ protected function prepareResults(StatementInterface $found) {
$extra = $this->moduleHandler->invokeAll('node_search_result', array($node, $item->langcode));
$language = language_load($item->langcode);
$language = $this->languageManager->getLanguage($item->langcode);
$username = array(
'#theme' => 'username',
'#account' => $node->getOwner(),
......@@ -486,7 +498,7 @@ public function searchFormAlter(array &$form, FormStateInterface $form_state) {
// Add languages.
$language_options = array();
$language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL);
$language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
foreach ($language_list as $langcode => $language) {
// Make locked languages appear special in the list.
$language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName();
......
......@@ -44,7 +44,7 @@ public function render(ResultRow $values) {
// @todo: Drupal Core dropped native language until config translation is
// ready, see http://drupal.org/node/1616594.
$value = $this->getValue($values);
$language = language_load($value);
$language = \Drupal::languageManager()->getLanguage($value);
$value = $language ? $language->getName() : '';
return $this->renderLink($value, $values);
}
......
......@@ -37,7 +37,7 @@ protected function setUp() {
* Tests CRUD operations.
*/
function testCRUD() {
$default_langcode = language_default()->getId();
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
// Verify default properties on a newly created empty entity.
$empty = entity_create('entity_test_label');
$this->assertIdentical($empty->id->value, NULL);
......
......@@ -535,7 +535,7 @@ function hook_tokens($type, $tokens, array $data = array(), array $options = arr
$url_options = array('absolute' => TRUE);
if (isset($options['langcode'])) {
$url_options['language'] = language_load($options['langcode']);
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
$langcode = $options['langcode'];
}
else {
......@@ -608,7 +608,7 @@ function hook_tokens_alter(array &$replacements, array $context) {
$options = $context['options'];
if (isset($options['langcode'])) {
$url_options['language'] = language_load($options['langcode']);
$url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
$langcode = $options['langcode'];
}
else {
......
......@@ -92,7 +92,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
$url_options = array('absolute' => TRUE);
if (isset($options['langcode'])) {