Issue #2561273 by stefan.r, joelpittet: "Text on demand" for "input required" exposed form plugin is not displayed
parent
f617434ee8
commit
c3c61bc269
|
@ -73,6 +73,9 @@ class InputRequired extends ExposedFormPluginBase {
|
|||
}
|
||||
|
||||
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',
|
||||
|
@ -81,14 +84,22 @@ class InputRequired extends ExposedFormPluginBase {
|
|||
'label' => '',
|
||||
'relationship' => 'none',
|
||||
'group_type' => 'group',
|
||||
'content' => $this->options['text_input_required'],
|
||||
'format' => $this->options['text_input_required_format'],
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,6 +193,31 @@ class ExposedFormTest extends ViewTestBase {
|
|||
$this->assertEqual(count($rows), 5, 'All rows are displayed by default when input is provided.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the "on demand text" for the input required exposed form type.
|
||||
*/
|
||||
public function testTextInputRequired() {
|
||||
$view = Views::getView('test_exposed_form_buttons');
|
||||
$display = &$view->storage->getDisplay('default');
|
||||
$display['display_options']['exposed_form']['type'] = 'input_required';
|
||||
// Set up the "on demand text".
|
||||
// @see https://www.drupal.org/node/535868
|
||||
$on_demand_text = 'Select any filter and click Apply to see results.';
|
||||
$display['display_options']['exposed_form']['options']['text_input_required'] = $on_demand_text;
|
||||
$display['display_options']['exposed_form']['options']['text_input_required_format'] = filter_default_format();
|
||||
$view->save();
|
||||
|
||||
// Ensure that the "on demand text" is displayed when no exposed filters are
|
||||
// applied.
|
||||
$this->drupalGet('test_exposed_form_buttons');
|
||||
$this->assertText('Select any filter and click Apply to see results.');
|
||||
|
||||
// Ensure that the "on demand text" is not displayed when an exposed filter
|
||||
// is applied.
|
||||
$this->drupalGet('test_exposed_form_buttons', array('query' => array('type' => 'article')));
|
||||
$this->assertNoText($on_demand_text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests exposed forms with exposed sort and items per page.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue