reverted: --- b/core/includes/bootstrap.inc +++ a/core/includes/bootstrap.inc @@ -1223,6 +1223,25 @@ } /** + * Returns a list of languages set up on the site. + * + * @param $flags + * (optional) Specifies the state of the languages that have to be returned. + * It can be: LanguageInterface::STATE_CONFIGURABLE, + * LanguageInterface::STATE_LOCKED, LanguageInterface::STATE_ALL. + * + * @return \Drupal\Core\Language\LanguageInterface[] + * An associative array of languages, keyed by the language code, ordered by + * weight ascending and name ascending. + * + * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0. + * Use \Drupal::languageManager()->getLanguages(). + */ +function language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { + return \Drupal::languageManager()->getLanguages($flags); +} + +/** * Loads a language object from the database. * * @param string $langcode diff -u b/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php --- b/core/modules/language/src/Plugin/Condition/Language.php +++ b/core/modules/language/src/Plugin/Condition/Language.php @@ -10,6 +10,9 @@ use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a 'Language' condition. @@ -23,16 +26,54 @@ * ) * */ -class Language extends ConditionPluginBase { +class Language extends ConditionPluginBase implements ContainerFactoryPluginInterface { + + /** + * The Language manager. + * + * @var \Drupal\Core\Language\LanguageManagerInterface + */ + protected $languageManager; + + /** + * Creates a new NodeType instance. + * + * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager + * The language manager. + * @param array $configuration + * The plugin configuration, i.e. an array with configuration values keyed + * by configuration option name. The special key 'context' may be used to + * initialize the defined contexts by setting it to an array of context + * values keyed by context names. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + */ + public function __construct(LanguageManagerInterface $language_manager, array $configuration, $plugin_id, $plugin_definition) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->languageManager = $language_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $container->get('language_manager'), + $configuration, + $plugin_id, + $plugin_definition + ); + } /** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $language_manager = \Drupal::languageManager(); - if ($language_manager->isMultilingual()) { + if ($this->languageManager->isMultilingual()) { // Fetch languages. - $languages = $language_manager->getLanguages(); + $languages = $this->languageManager->getLanguages(); $langcodes_options = array(); foreach ($languages as $language) { $langcodes_options[$language->id] = $language->getName(); @@ -66,7 +107,7 @@ * {@inheritdoc} */ public function summary() { - $language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); + $language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL); $selected = $this->configuration['langcodes']; // Reduce the language list to an array of language names. $language_names = array_reduce($language_list, function(&$result, $item) use ($selected) {