diff -u b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php --- b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php +++ b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php @@ -8,9 +8,7 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\Routing\PathBasedGeneratorInterface; -use Drupal\Core\StringTranslation\Translator\TranslatorInterface; use Drupal\locale\Form\TranslateEditForm; use Drupal\locale\Form\TranslateFilterForm; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -95,8 +93,8 @@ */ public function translatePage() { return array( - 'filter' => drupal_get_form(TranslateFilterForm::create($this->container)), - 'form' => drupal_get_form(TranslateEditForm::create($this->container)), + 'filter' => TranslateFilterForm::create($this->container), + 'form' => TranslateEditForm::create($this->container), ); } } diff -u b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php --- b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php @@ -35,32 +35,15 @@ protected $translator; /** - * Constructs a TranslateEditFrom object. + * Injects the service container used by this 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\StringStorageInterface $locale_storage - * The locale storage for translations. + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The service container this object should use. */ - public function __construct(KeyValueStoreInterface $state, TranslatorInterface $translator, StringStorageInterface $locale_storage, Request $request) { - $this->state = $state; - $this->translator = $translator; - $this->localeStorage = $locale_storage; - $this->request = $request; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('keyvalue')->get('state'), - $container->get('string_translation'), - $container->get('locale.storage'), - $container->get('request') - ); + public function setContainer(ContainerInterface $container = NULL) { + parent::setContainer($container); + $this->state = $this->container->get('keyvalue')->get('state'); + $this->translator = $this->container->get('string_translation'); } /** diff -u b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php --- b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php @@ -7,12 +7,10 @@ namespace Drupal\locale\Form; -use Drupal\Core\Form\FormInterface; - /** * Provides a filtered translation edit form. */ -class TranslateFilterForm extends TranslateFormBase implements FormInterface { +class TranslateFilterForm extends TranslateFormBase { /** * {@inheritdoc} diff -u b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php --- b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFormBase.php @@ -7,10 +7,9 @@ namespace Drupal\locale\Form; -use Drupal\Core\Controller\ControllerInterface; +use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Drupal\Core\Form\FormInterface; use Drupal\Core\Language\Language; -use Drupal\locale\StringStorageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -19,7 +18,7 @@ * * Provides methods for searching and filtering strings. */ -abstract class TranslateFormBase implements ControllerInterface, FormInterface { +abstract class TranslateFormBase implements ContainerAwareInterface, FormInterface { /** * The locale storage. @@ -34,28 +33,53 @@ * @var \Symfony\Component\HttpFoundation\Request */ protected $request; + + /** + * The injection container for this object. + * + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Filter values. Shared between objects that inherite this class. + * + * @var array | null + */ + public static $filter_values = NULL; /** - * Constructs a new TranslationFormBase object. + * Injects the service container used by this object. * - * @param \Drupal\locale\StringStorageInterface $locale_storage - * The locale storage. - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The service container this object should use. */ - public function __construct(StringStorageInterface $locale_storage, Request $request) { - $this->localeStorage = $locale_storage; - $this->request = $request; + public function setContainer(ContainerInterface $container = NULL) { + $this->container = $container; + $this->localeStorage = $container->get('locale.storage'); + $this->request = $container->get('request'); } /** - * {@inheritdoc} + * Instantiates a new instance of this form. + * + * This is a factory method that returns a new instance of this object. The + * factory should pass any needed dependencies into the constructor of this + * object, but not the container itself. Every call to this method must return + * a new instance of this object; that is, it may not implement a singleton. + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The service container this object should use. */ public static function create(ContainerInterface $container) { - return new static( + $form = new static( $container->get('locale.storage'), $container->get('request') ); + $form->setContainer($container); + $renderable_form = drupal_get_form($form); + + return $renderable_form; } /** @@ -109,32 +133,34 @@ * @return array $filter_values * The filter values. */ - protected function translateFilterValues(Request $request) { - $filter_values = &drupal_static(__FUNCTION__); - if (!isset($filter_values)) { - $filter_values = array(); - $filters = $this->translateFilters(); - foreach ($filters as $key => $filter) { - $filter_values[$key] = $filter['default']; - // Let the filter defaults be overwritten by parameters in the URL. - if ($request->query->has($key)) { - // Only allow this value if it was among the options, or - // if there were no fixed options to filter for. - $value = $request->query->get($key); - if (!isset($filter['options']) || isset($filter['options'][$value])) { - $filter_values[$key] = $value; - } + protected function translateFilterValues(Request $request, $reset=FALSE) { + if (!$reset && self::$filter_values) { + return self::$filter_values; + } + + $filter_values = array(); + $filters = $this->translateFilters(); + foreach ($filters as $key => $filter) { + $filter_values[$key] = $filter['default']; + // Let the filter defaults be overwritten by parameters in the URL. + if ($request->query->has($key)) { + // Only allow this value if it was among the options, or + // if there were no fixed options to filter for. + $value = $request->query->get($key); + if (!isset($filter['options']) || isset($filter['options'][$value])) { + $filter_values[$key] = $value; } - elseif (isset($_SESSION['locale_translate_filter'][$key])) { - // Only allow this value if it was among the options, or - // if there were no fixed options to filter for. - if (!isset($filter['options']) || isset($filter['options'][$_SESSION['locale_translate_filter'][$key]])) { - $filter_values[$key] = $_SESSION['locale_translate_filter'][$key]; - } + } + elseif (isset($_SESSION['locale_translate_filter'][$key])) { + // Only allow this value if it was among the options, or + // if there were no fixed options to filter for. + if (!isset($filter['options']) || isset($filter['options'][$_SESSION['locale_translate_filter'][$key]])) { + $filter_values[$key] = $_SESSION['locale_translate_filter'][$key]; } } } - return $filter_values; + + return self::$filter_values = $filter_values; } /**