Commit 85c8f324 authored by Dries's avatar Dries
Browse files

Issue #2254495 by ParisLiakos, alexpott: Move language_admin_predefined_list...

Issue #2254495 by ParisLiakos, alexpott: Move language_admin_predefined_list to ConfigurableLanguageManager.
parent 2b9cec6d
...@@ -6,26 +6,8 @@ ...@@ -6,26 +6,8 @@
*/ */
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
/**
* Prepare a language code list for unused predefined languages.
*/
function language_admin_predefined_list() {
$languages = \Drupal::languageManager()->getLanguages();
$predefined = LanguageManager::getStandardLanguageList();
foreach ($predefined as $key => $value) {
if (isset($languages[$key])) {
unset($predefined[$key]);
continue;
}
$predefined[$key] = t($value[0]);
}
asort($predefined);
return $predefined;
}
/** /**
* Returns HTML for the language negotiation configuration form. * Returns HTML for the language negotiation configuration form.
* *
......
...@@ -407,4 +407,21 @@ public function getLanguageConfigOverride($langcode, $name) { ...@@ -407,4 +407,21 @@ public function getLanguageConfigOverride($langcode, $name) {
return $this->configFactoryOverride->getOverride($langcode, $name); return $this->configFactoryOverride->getOverride($langcode, $name);
} }
/**
* {@inheritdoc}
*/
public function getUnusedPredefinedList() {
$languages = $this->getLanguages();
$predefined = $this->getStandardLanguageList();
foreach ($predefined as $key => $value) {
if (isset($languages[$key])) {
unset($predefined[$key]);
continue;
}
$predefined[$key] = $this->t($value[0]);
}
asort($predefined);
return $predefined;
}
} }
...@@ -96,4 +96,12 @@ public function updateLockedLanguageWeights(); ...@@ -96,4 +96,12 @@ public function updateLockedLanguageWeights();
*/ */
public function getLanguageConfigOverride($langcode, $name); public function getLanguageConfigOverride($langcode, $name);
/**
* Prepare a language code list for unused predefined languages.
*
* @return array
* List of predefined language names keyed by langcode.
*/
public function getUnusedPredefinedList();
} }
...@@ -29,8 +29,7 @@ public function getFormId() { ...@@ -29,8 +29,7 @@ public function getFormId() {
public function form(array $form, array &$form_state) { public function form(array $form, array &$form_state) {
$form['#title'] = $this->t('Add language'); $form['#title'] = $this->t('Add language');
$this->moduleHandler->loadInclude('language', 'inc', 'language.admin'); $predefined_languages = $this->languageManager->getUnusedPredefinedList();
$predefined_languages = language_admin_predefined_list();
$predefined_languages['custom'] = $this->t('Custom language...'); $predefined_languages['custom'] = $this->t('Custom language...');
$predefined_default = !empty($form_state['values']['predefined_langcode']) ? $form_state['values']['predefined_langcode'] : key($predefined_languages); $predefined_default = !empty($form_state['values']['predefined_langcode']) ? $form_state['values']['predefined_langcode'] : key($predefined_languages);
......
...@@ -10,12 +10,40 @@ ...@@ -10,12 +10,40 @@
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Base form for language add and edit forms. * Base form for language add and edit forms.
*/ */
abstract class LanguageFormBase extends EntityForm { abstract class LanguageFormBase extends EntityForm {
/**
* The configurable language manager.
*
* @var \Drupal\language\ConfigurableLanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a ContentEntityForm object.
*
* @param \Drupal\language\ConfigurableLanguageManagerInterface $language_manager
* The configurable language manager.
*/
public function __construct(ConfigurableLanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('language_manager')
);
}
/** /**
* Common elements of the language addition and editing form. * Common elements of the language addition and editing form.
*/ */
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
namespace Drupal\language\Form; namespace Drupal\language\Form;
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
class NegotiationBrowserForm extends ConfigFormBase { class NegotiationBrowserForm extends ConfigFormBase {
/** /**
* The module handler. * The configurable language manager.
* *
* @var \Drupal\Core\Extension\ModuleHandlerInterface * @var \Drupal\language\ConfigurableLanguageManagerInterface
*/ */
protected $moduleHandler; protected $languageManager;
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -30,9 +30,9 @@ class NegotiationBrowserForm extends ConfigFormBase { ...@@ -30,9 +30,9 @@ class NegotiationBrowserForm extends ConfigFormBase {
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler * The module handler
*/ */
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) { public function __construct(ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager ) {
parent::__construct($config_factory); parent::__construct($config_factory);
$this->moduleHandler = $module_handler; $this->languageManager = $language_manager;
} }
/** /**
...@@ -41,7 +41,7 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle ...@@ -41,7 +41,7 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('config.factory'), $container->get('config.factory'),
$container->get('module_handler') $container->get('language_manager')
); );
} }
...@@ -56,7 +56,6 @@ public function getFormId() { ...@@ -56,7 +56,6 @@ public function getFormId() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, array &$form_state) {
$this->moduleHandler->loadInclude('language', 'inc', 'language.admin');
$form = array(); $form = array();
// Initialize a language list to the ones available, including English. // Initialize a language list to the ones available, including English.
...@@ -71,12 +70,12 @@ public function buildForm(array $form, array &$form_state) { ...@@ -71,12 +70,12 @@ public function buildForm(array $form, array &$form_state) {
// only. If we do have already added languages, set up two option groups with // only. If we do have already added languages, set up two option groups with
// the list of existing and then predefined languages. // the list of existing and then predefined languages.
if (empty($existing_languages)) { if (empty($existing_languages)) {
$language_options = language_admin_predefined_list(); $language_options = $this->languageManager->getUnusedPredefinedList();
} }
else { else {
$language_options = array( $language_options = array(
$this->t('Existing languages') => $existing_languages, $this->t('Existing languages') => $existing_languages,
$this->t('Languages not yet added') => language_admin_predefined_list() $this->t('Languages not yet added') => $this->languageManager->getUnusedPredefinedList()
); );
} }
......
...@@ -8,16 +8,15 @@ ...@@ -8,16 +8,15 @@
namespace Drupal\locale\Form; namespace Drupal\locale\Form;
use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManagerInterface; use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Form constructor for the translation import screen. * Form constructor for the translation import screen.
*/ */
class ImportForm extends FormBase implements ContainerInjectionInterface { class ImportForm extends FormBase {
/** /**
* Uploaded file entity. * Uploaded file entity.
...@@ -25,6 +24,7 @@ class ImportForm extends FormBase implements ContainerInjectionInterface { ...@@ -25,6 +24,7 @@ class ImportForm extends FormBase implements ContainerInjectionInterface {
* @var \Drupal\file\Entity\File * @var \Drupal\file\Entity\File
*/ */
protected $file; protected $file;
/** /**
* The module handler service. * The module handler service.
* *
...@@ -33,9 +33,9 @@ class ImportForm extends FormBase implements ContainerInjectionInterface { ...@@ -33,9 +33,9 @@ class ImportForm extends FormBase implements ContainerInjectionInterface {
protected $moduleHandler; protected $moduleHandler;
/** /**
* The language manager. * The configurable language manager.
* *
* @var \Drupal\Core\Language\LanguageManagerInterface * @var \Drupal\language\ConfigurableLanguageManagerInterface
*/ */
protected $languageManager; protected $languageManager;
...@@ -53,10 +53,10 @@ public static function create(ContainerInterface $container) { ...@@ -53,10 +53,10 @@ public static function create(ContainerInterface $container) {
* *
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service. * The module handler service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * @param \Drupal\language\ConfigurableLanguageManagerInterface $language_manager
* The language manager. * The configurable language manager.
*/ */
public function __construct(ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { public function __construct(ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager) {
$this->moduleHandler = $module_handler; $this->moduleHandler = $module_handler;
$this->languageManager = $language_manager; $this->languageManager = $language_manager;
} }
...@@ -88,16 +88,15 @@ public function buildForm(array $form, array &$form_state) { ...@@ -88,16 +88,15 @@ public function buildForm(array $form, array &$form_state) {
// If we have no languages available, present the list of predefined // If we have no languages available, present the list of predefined
// languages only. If we do have already added languages, set up two option // languages only. If we do have already added languages, set up two option
// groups with the list of existing and then predefined languages. // groups with the list of existing and then predefined languages.
form_load_include($form_state, 'inc', 'language', 'language.admin');
if (empty($existing_languages)) { if (empty($existing_languages)) {
$language_options = language_admin_predefined_list(); $language_options = $this->languageManager->getUnusedPredefinedList();
$default = key($language_options); $default = key($language_options);
} }
else { else {
$default = key($existing_languages); $default = key($existing_languages);
$language_options = array( $language_options = array(
$this->t('Existing languages') => $existing_languages, $this->t('Existing languages') => $existing_languages,
$this->t('Languages not yet added') => language_admin_predefined_list() $this->t('Languages not yet added') => $this->languageManager->getUnusedPredefinedList()
); );
} }
......
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