You are here

protected function TranslateFormBase::translateFilterValues in Drupal 9

Same name and namespace in other branches
  1. 8 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();
  $request = $this
    ->getRequest();
  $session_filters = $request
    ->getSession()
    ->get('locale_translate_filter', []);
  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_filters[$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_filters[$key]])) {
        $filter_values[$key] = $session_filters[$key];
      }
    }
  }
  return static::$filterValues = $filter_values;
}