diff --git a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php index a3d2b32..cccbcea 100644 --- a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php +++ b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php @@ -96,8 +96,8 @@ public function checkTranslation() { public function translatePage() { $state = $this->container->get('keyvalue')->get('state'); return array( - 'filter' => drupal_get_form(new TranslateFilterForm($state)), - 'form' => drupal_get_form(new TranslateEditForm($state, $this->container->get('string_translation'), $this->container->get('locale.storage'))), + 'filter' => TranslateFilterForm::create($this->container), + 'form' => TranslateEditForm::create($this->container), ); } } diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php index 8bd86bb..8cceda8 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php @@ -12,8 +12,8 @@ use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\StringTranslation\Translator\TranslatorInterface; use Drupal\locale\SourceString; -use Drupal\locale\StringDatabaseStorage; -use Drupal\node\NodeInterface; +use Drupal\locale\StringStorageInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -36,26 +36,30 @@ class TranslateEditForm extends TranslateFormBase implements FormInterface { protected $translator; /** - * The locale storage. - * - * @var \Drupal\locale\StringDatabaseStorage - */ - protected $localStorage; - - /** * Constructs a TranslateEditFrom object. * * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state * The state key/value store. * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator * The translator service. - * @param \Drupal\locale\StringDatabaseStorage $local_storage - * The local storage for translations. + * @param \Drupal\locale\StringStorageInterface $locale_storage + * The locale storage for translations. */ - public function __construct(KeyValueStoreInterface $state, TranslatorInterface $translator, StringDatabaseStorage $local_storage) { + public function __construct(KeyValueStoreInterface $state, TranslatorInterface $translator, StringStorageInterface $locale_storage) { $this->state = $state; $this->translator = $translator; - $this->localStorage = $local_storage; + $this->localeStorage = $locale_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('keyvalue')->get('state'), + $container->get('string_translation'), + $container->get('locale.storage') + ); } /** @@ -68,8 +72,8 @@ public function getFormID() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, NodeInterface $node = NULL) { - $filter_values = $this->translateFilterValues(); + public function buildForm(array $form, array &$form_state) { + $filter_values = $this->translateFilterValues($this->request); $langcode = $filter_values['langcode']; drupal_static_reset('language_list'); @@ -96,7 +100,7 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = ); if (isset($langcode)) { - $strings = $this->translateFilterLoadStrings(); + $strings = $this->translateFilterLoadStrings($this->request); $plural_formulas = $this->state->get('locale.translation.plurals') ?: array(); @@ -220,7 +224,7 @@ public function submitForm(array &$form, array &$form_state, Request $request = // Preload all translations for strings in the form. $lids = array_keys($form_state['values']['strings']); $existing_translation_objects = array(); - foreach ($this->localStorage->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { + foreach ($this->localeStorage->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { $existing_translation_objects[$existing_translation_object->lid] = $existing_translation_object; } @@ -249,7 +253,7 @@ public function submitForm(array &$form, array &$form_state, Request $request = if ($is_changed) { // Only update or insert if we have a value to use. - $target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : $this->localStorage->createTranslation(array('lid' => $lid, 'language' => $langcode)); + $target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : $this->localeStorage->createTranslation(array('lid' => $lid, 'language' => $langcode)); $target->setPlurals($new_translation['translations']) ->setCustomized() ->save(); diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php index e02819c..92ca824 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php @@ -24,9 +24,9 @@ public function getFormID() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, Node $node = NULL) { + public function buildForm(array $form, array &$form_state) { $filters = $this->translateFilters(); - $filter_values = $this->translateFilterValues(); + $filter_values = $this->translateFilterValues($this->request); $form['#attached']['css'] = array( drupal_get_path('module', 'locale') . '/locale.admin.css', diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php index 5b2abbd..a421285 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php @@ -29,13 +29,23 @@ protected $localeStorage; /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** * Constructs a new TranslationFormBase object. * * @param \Drupal\locale\StringStorageInterface $locale_storage * The locale storage. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. */ - public function __construct(StringStorageInterface $locale_storage) { + public function __construct(StringStorageInterface $locale_storage, Request $request) { $this->localeStorage = $locale_storage; + $this->request = $request; } /** @@ -43,7 +53,8 @@ public function __construct(StringStorageInterface $locale_storage) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('locale.storage') + $container->get('locale.storage'), + $container->get('request') ); } @@ -51,7 +62,7 @@ public static function create(ContainerInterface $container) { * Builds a string search query and returns an array of string objects. * * @param \Symfony\Component\HttpFoundation\Request $request - * The current request object. + * The current request object. * * @return array * Array of \Drupal\locale\TranslationString objects. @@ -99,9 +110,6 @@ protected function translateFilterLoadStrings(Request $request) { * The filter values. */ protected function translateFilterValues(Request $request) { - // @todo vlikin: Need be decoupled. - $request = \Drupal::request(); - $filter_values = &drupal_static(__FUNCTION__); if (!isset($filter_values)) { $filter_values = array();