function FilterPluginBase::exposedTranslate

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::exposedTranslate()
  2. 10 core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::exposedTranslate()
  3. 11.x core/modules/views/src/Plugin/views/filter/FilterPluginBase.php \Drupal\views\Plugin\views\filter\FilterPluginBase::exposedTranslate()

Make some translations to a form item to make it more suitable to exposing.

1 call to FilterPluginBase::exposedTranslate()
FilterPluginBase::buildExposedForm in core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
Render our chunk of the exposed filter form when selecting

File

core/modules/views/src/Plugin/views/filter/FilterPluginBase.php, line 1223

Class

FilterPluginBase
Base class for Views filters handler plugins.

Namespace

Drupal\views\Plugin\views\filter

Code

protected function exposedTranslate(&$form, $type) {
    if (!isset($form['#type'])) {
        return;
    }
    if ($form['#type'] == 'radios') {
        $form['#type'] = 'select';
    }
    // Checkboxes don't work so well in exposed forms due to GET conversions.
    if ($form['#type'] == 'checkboxes') {
        if (empty($form['#no_convert']) || empty($this->options['expose']['multiple'])) {
            $form['#type'] = 'select';
        }
        if (!empty($this->options['expose']['multiple'])) {
            $form['#multiple'] = TRUE;
        }
    }
    if (empty($this->options['expose']['multiple']) && isset($form['#multiple'])) {
        unset($form['#multiple']);
        $form['#size'] = NULL;
    }
    // Cleanup in case the translated element's (radios or checkboxes) display value contains html.
    if ($form['#type'] == 'select') {
        $this->prepareFilterSelectOptions($form['#options']);
    }
    if ($type == 'value' && empty($this->always_required) && empty($this->options['expose']['required']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
        $form['#options'] = [
            'All' => $this->t('- Any -'),
        ] + $form['#options'];
        $form['#default_value'] = 'All';
    }
    if (!empty($this->options['expose']['required'])) {
        $form['#required'] = TRUE;
    }
}

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