You are here

public function InputRequired::preRender in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Plugin/views/exposed_form/InputRequired.php \Drupal\views\Plugin\views\exposed_form\InputRequired::preRender()

Overrides ExposedFormPluginBase::preRender

File

core/modules/views/src/Plugin/views/exposed_form/InputRequired.php, line 75
Contains \Drupal\views\Plugin\views\exposed_form\InputRequired.

Class

InputRequired
Exposed form plugin that provides an exposed form with required input.

Namespace

Drupal\views\Plugin\views\exposed_form

Code

public function preRender($values) {

  // Display the "text on demand" if needed. This is a site builder-defined
  // text to display instead of results until the user selects and applies
  // an exposed filter.
  if (!$this
    ->exposedFilterApplied()) {
    $options = array(
      'id' => 'area',
      'table' => 'views',
      'field' => 'area',
      'label' => '',
      'relationship' => 'none',
      'group_type' => 'group',
      // We need to set the "Display even if view has no result" option to
      // TRUE as the input required exposed form plugin will always force an
      // empty result if no exposed filters are applied.
      'empty' => TRUE,
      'content' => [
        // @see \Drupal\views\Plugin\views\area\Text::render()
        'value' => $this->options['text_input_required'],
        'format' => $this->options['text_input_required_format'],
      ],
    );
    $handler = Views::handlerManager('area')
      ->getHandler($options);
    $handler
      ->init($this->view, $this->displayHandler, $options);
    $this->displayHandler->handlers['empty'] = array(
      'area' => $handler,
    );

    // Override the existing empty result message (if applicable).
    $this->displayHandler
      ->setOption('empty', array(
      'text' => $options,
    ));
  }
}