function SortPluginBase::showExposeButton

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/sort/SortPluginBase.php \Drupal\views\Plugin\views\sort\SortPluginBase::showExposeButton()
  2. 8.9.x core/modules/views/src/Plugin/views/sort/SortPluginBase.php \Drupal\views\Plugin\views\sort\SortPluginBase::showExposeButton()
  3. 10 core/modules/views/src/Plugin/views/sort/SortPluginBase.php \Drupal\views\Plugin\views\sort\SortPluginBase::showExposeButton()

Shortcut to display the expose/hide button.

Overrides HandlerBase::showExposeButton

1 call to SortPluginBase::showExposeButton()
SortPluginBase::buildOptionsForm in core/modules/views/src/Plugin/views/sort/SortPluginBase.php
Basic options for all sort criteria.

File

core/modules/views/src/Plugin/views/sort/SortPluginBase.php, line 96

Class

SortPluginBase
Base sort handler that has no options and performs a simple sort.

Namespace

Drupal\views\Plugin\views\sort

Code

public function showExposeButton(&$form, FormStateInterface $form_state) {
    $form['expose_button'] = [
        '#prefix' => '<div class="views-expose clearfix">',
        '#suffix' => '</div>',
        // Should always come first
'#weight' => -1000,
    ];
    // Add a checkbox for JS users, which will have behavior attached to it
    // so it can replace the button.
    $form['expose_button']['checkbox'] = [
        '#theme_wrappers' => [
            'container',
        ],
        '#attributes' => [
            'class' => [
                'js-only',
            ],
        ],
    ];
    $form['expose_button']['checkbox']['checkbox'] = [
        '#title' => $this->t('Expose this sort to visitors, to allow them to change it'),
        '#type' => 'checkbox',
    ];
    // Then add the button itself.
    if (empty($this->options['exposed'])) {
        $form['expose_button']['markup'] = [
            '#markup' => '<div class="description exposed-description" style="float: left; margin-right:10px">' . $this->t('This sort is not exposed. Expose it to allow the users to change it.') . '</div>',
        ];
        $form['expose_button']['button'] = [
            '#limit_validation_errors' => [],
            '#type' => 'submit',
            '#value' => $this->t('Expose sort'),
            '#submit' => [
                [
                    $this,
                    'displayExposedForm',
                ],
            ],
        ];
        $form['expose_button']['checkbox']['checkbox']['#default_value'] = 0;
    }
    else {
        $form['expose_button']['markup'] = [
            '#markup' => '<div class="description exposed-description">' . $this->t('This sort is exposed. If you hide it, users will not be able to change it.') . '</div>',
        ];
        $form['expose_button']['button'] = [
            '#limit_validation_errors' => [],
            '#type' => 'submit',
            '#value' => $this->t('Hide sort'),
            '#submit' => [
                [
                    $this,
                    'displayExposedForm',
                ],
            ],
        ];
        $form['expose_button']['checkbox']['checkbox']['#default_value'] = 1;
    }
}

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