diff --git c/core/modules/locale/lib/Drupal/locale/Form/ImportForm.php w/core/modules/locale/lib/Drupal/locale/Form/ImportForm.php index 0f19427..43e3fd8 100644 --- c/core/modules/locale/lib/Drupal/locale/Form/ImportForm.php +++ w/core/modules/locale/lib/Drupal/locale/Form/ImportForm.php @@ -7,20 +7,37 @@ namespace Drupal\locale\Form; -use Drupal\Core\Form\FormInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Form\FormBase; use Drupal\Core\Language\Language; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form constructor for the translation import screen. */ -class ImportForm implements FormInterface { +class ImportForm extends FormBase implements ContainerInjectionInterface { + /** + * Module Handler Service. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + /** + * {@inheritdoc} + */ public static function create(ContainerInterface $container) { - return new static(); + return new static( + $container->get('module_handler') + ); } - - public function __construct() { + /** + * Constructs an ImportForm. + * + * @param $module_handler \Drupal\Core\Extension\ModuleHandlerInterface + */ + public function __construct(ModuleHandlerInterface $module_handler) { + $this->moduleHandler = $module_handler; } /** @@ -39,7 +56,6 @@ public function getFormID() { * @ingroup forms */ public function buildForm(array $form, array &$form_state) { - drupal_static_reset('language_list'); $languages = language_list(); // Initialize a language list to the ones available, including English if we @@ -62,8 +78,8 @@ public function buildForm(array $form, array &$form_state) { else { $default = key($existing_languages); $language_options = array( - t('Existing languages') => $existing_languages, - t('Languages not yet added') => language_admin_predefined_list() + $this->t('Existing languages') => $existing_languages, + $this->t('Languages not yet added') => language_admin_predefined_list() ); } @@ -73,8 +89,8 @@ public function buildForm(array $form, array &$form_state) { ); $form['file'] = array( '#type' => 'file', - '#title' => t('Translation file'), - '#description' => theme('file_upload_help', array('description' => t('A Gettext Portable Object file.'), 'upload_validators' => $validators)), + '#title' => $this->t('Translation file'), + '#description' => theme('file_upload_help', array('description' => $this->t('A Gettext Portable Object file.'), 'upload_validators' => $validators)), '#size' => 50, '#upload_validators' => $validators, '#attributes' => array('class' => array('file-import-input')), @@ -86,14 +102,14 @@ public function buildForm(array $form, array &$form_state) { ); $form['langcode'] = array( '#type' => 'select', - '#title' => t('Language'), + '#title' => $this->t('Language'), '#options' => $language_options, '#default_value' => $default, '#attributes' => array('class' => array('langcode-input')), ); $form['customized'] = array( - '#title' => t('Treat imported strings as custom translations'), + '#title' => $this->t('Treat imported strings as custom translations'), '#type' => 'checkbox', ); $form['overwrite_options'] = array( @@ -101,7 +117,7 @@ public function buildForm(array $form, array &$form_state) { '#tree' => TRUE, ); $form['overwrite_options']['not_customized'] = array( - '#title' => t('Overwrite non-customized translations'), + '#title' => $this->t('Overwrite non-customized translations'), '#type' => 'checkbox', '#states' => array( 'checked' => array( @@ -110,7 +126,7 @@ public function buildForm(array $form, array &$form_state) { ), ); $form['overwrite_options']['customized'] = array( - '#title' => t('Overwrite existing customized translations'), + '#title' => $this->t('Overwrite existing customized translations'), '#type' => 'checkbox', ); @@ -119,7 +135,7 @@ public function buildForm(array $form, array &$form_state) { ); $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Import') + '#value' => $this->t('Import') ); return $form; } @@ -127,12 +143,6 @@ public function buildForm(array $form, array &$form_state) { /** * {@inheritdoc} */ - public function validateForm(array &$form, array &$form_state) { - } - - /** - * {@inheritdoc} - */ public function submitForm(array &$form, array &$form_state) { // Ensure we have the file uploaded. if ($file = file_save_upload('file', $form['file']['#upload_validators'], 'translations://', 0)) { @@ -144,20 +154,20 @@ public function submitForm(array &$form, array &$form_state) { 'langcode' => $form_state['values']['langcode'] )); $language = language_save($language); - drupal_set_message(t('The language %language has been created and can now be used.', array('%language' => $language->name))); + drupal_set_message($this->t('The language %language has been created and can now be used.', array('%language' => $language->name))); } $options = array( 'langcode' => $form_state['values']['langcode'], 'overwrite_options' => $form_state['values']['overwrite_options'], 'customized' => $form_state['values']['customized'] ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED, ); - \Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc'); + $this->moduleHandler->loadInclude('locale', 'bulk.inc'); $file = locale_translate_file_attach_properties($file, $options); $batch = locale_translate_batch_build(array($file->uri => $file), $options); batch_set($batch); } else { - form_set_error('file', t('File to import not found.')); + form_set_error('file', $this->t('File to import not found.')); $form_state['rebuild'] = TRUE; return; }