You are here

protected function TranslateFormBase::translateFilterValues in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/locale/src/Form/TranslateFormBase.php \Drupal\locale\Form\TranslateFormBase::translateFilterValues()

Builds an array out of search criteria specified in request variables.

Parameters

bool $reset: If the list of values should be reset.

Return value

array The filter values.

3 calls to TranslateFormBase::translateFilterValues()
TranslateEditForm::buildForm in core/modules/locale/src/Form/TranslateEditForm.php
Form constructor.
TranslateFilterForm::buildForm in core/modules/locale/src/Form/TranslateFilterForm.php
Form constructor.
TranslateFormBase::translateFilterLoadStrings in core/modules/locale/src/Form/TranslateFormBase.php
Builds a string search query and returns an array of string objects.

File

core/modules/locale/src/Form/TranslateFormBase.php, line 121

Class

TranslateFormBase
Defines the locale user interface translation form base.

Namespace

Drupal\locale\Form

Code

protected function translateFilterValues($reset = FALSE) {
  if (!$reset && static::$filterValues) {
    return static::$filterValues;
  }
  $filter_values = [];
  $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 ($this
      ->getRequest()->query
      ->has($key)) {

      // Only allow this value if it was among the options, or
      // if there were no fixed options to filter for.
      $value = $this
        ->getRequest()->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];
      }
    }
  }
  return static::$filterValues = $filter_values;
}