public function InputRequired::preRender in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/exposed_form/InputRequired.php \Drupal\views\Plugin\views\exposed_form\InputRequired::preRender()
- 9 core/modules/views/src/Plugin/views/exposed_form/InputRequired.php \Drupal\views\Plugin\views\exposed_form\InputRequired::preRender()
Runs before the view is rendered.
Implement if your exposed form needs to run code before the view is rendered.
Parameters
\Drupal\views\ResultRow[] $values: An array of all ResultRow objects returned from the query.
Overrides ExposedFormPluginBase::preRender
See also
\Drupal\views\ViewExecutable::render()
File
- core/
modules/ views/ src/ Plugin/ views/ exposed_form/ InputRequired.php, line 70
Class
- InputRequired
- Exposed form plugin that provides an exposed form with required input.
Namespace
Drupal\views\Plugin\views\exposed_formCode
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 = [
'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'] = [
'area' => $handler,
];
// Override the existing empty result message (if applicable).
$this->displayHandler
->setOption('empty', [
'text' => $options,
]);
}
}