function TranslateFormBase::translateFilters

Same name and namespace in other branches
  1. 9 core/modules/locale/src/Form/TranslateFormBase.php \Drupal\locale\Form\TranslateFormBase::translateFilters()
  2. 8.9.x core/modules/locale/src/Form/TranslateFormBase.php \Drupal\locale\Form\TranslateFormBase::translateFilters()
  3. 10 core/modules/locale/src/Form/TranslateFormBase.php \Drupal\locale\Form\TranslateFormBase::translateFilters()

Lists locale translation filters that can be applied.

3 calls to TranslateFormBase::translateFilters()
TranslateFilterForm::buildForm in core/modules/locale/src/Form/TranslateFilterForm.php
Form constructor.
TranslateFilterForm::submitForm in core/modules/locale/src/Form/TranslateFilterForm.php
Form submission handler.
TranslateFormBase::translateFilterValues in core/modules/locale/src/Form/TranslateFormBase.php
Builds an array out of search criteria specified in request variables.

File

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

Class

TranslateFormBase
Defines the locale user interface translation form base.

Namespace

Drupal\locale\Form

Code

protected function translateFilters() {
    $filters = [];
    // Get all languages, except English.
    $this->languageManager
        ->reset();
    $languages = $this->languageManager
        ->getLanguages();
    $language_options = [];
    foreach ($languages as $langcode => $language) {
        if (locale_is_translatable($langcode)) {
            $language_options[$langcode] = $language->getName();
        }
    }
    // Pick the current interface language code for the filter.
    $default_langcode = $this->languageManager
        ->getCurrentLanguage()
        ->getId();
    if (!isset($language_options[$default_langcode])) {
        $available_langcodes = array_keys($language_options);
        $default_langcode = array_shift($available_langcodes);
    }
    $filters['string'] = [
        'title' => $this->t('String contains'),
        'description' => $this->t('Leave blank to show all strings. The search is case sensitive.'),
        'default' => '',
    ];
    $filters['langcode'] = [
        'title' => $this->t('Translation language'),
        'options' => $language_options,
        'default' => $default_langcode,
    ];
    $filters['translation'] = [
        'title' => $this->t('Search in'),
        'options' => [
            'all' => $this->t('Both translated and untranslated strings'),
            'translated' => $this->t('Only translated strings'),
            'untranslated' => $this->t('Only untranslated strings'),
        ],
        'default' => 'all',
    ];
    $filters['customized'] = [
        'title' => $this->t('Translation type'),
        'options' => [
            'all' => $this->t('All'),
            LOCALE_NOT_CUSTOMIZED => $this->t('Non-customized translation'),
            LOCALE_CUSTOMIZED => $this->t('Customized translation'),
        ],
        'states' => [
            'visible' => [
                ':input[name=translation]' => [
                    'value' => 'translated',
                ],
            ],
        ],
        'default' => 'all',
    ];
    return $filters;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.