Commit 0d71430c authored by catch's avatar catch

Issue #2361481 by Lendude, evanjenkins, xjm, dawehner, Zekvyrin: Argument...

Issue #2361481 by Lendude, evanjenkins, xjm, dawehner, Zekvyrin: Argument validations doesn't set the block title anymore
parent c271cea0
......@@ -27,11 +27,6 @@ public function build() {
// entry for the view output by passing FALSE, because we're going to cache
// the whole block instead.
if ($output = $this->view->buildRenderable($this->displayID, [], FALSE)) {
// Override the label to the dynamic title configured in the view.
if (empty($this->configuration['views_label']) && $this->view->getTitle()) {
$output['#title'] = ['#markup' => $this->view->getTitle(), '#allowed_tags' => Xss::getHtmlTagList()];
}
// Before returning the block output, convert it to a renderable array
// with contextual links.
$this->addContextualLinks($output);
......@@ -41,6 +36,11 @@ public function build() {
// #pre_render callback has already been applied.
$output = View::preRenderViewElement($output);
// Override the label to the dynamic title configured in the view.
if (empty($this->configuration['views_label']) && $this->view->getTitle()) {
$output['#title'] = ['#markup' => $this->view->getTitle(), '#allowed_tags' => Xss::getHtmlTagList()];
}
// When view_build is empty, the actual render array output for this View
// is going to be empty. In that case, return just #cache, so that the
// render system knows the reasons (cache contexts & tags) why this Views
......
......@@ -5,6 +5,7 @@
use Drupal\views\Plugin\Block\ViewsBlock;
use Drupal\views\Tests\ViewTestData;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
/**
* Tests native behaviors of the block views plugin.
......@@ -51,4 +52,68 @@ public function testMachineNameSuggestion() {
$this->assertEqual($views_block->getMachineNameSuggestion(), 'views_block__test_view_block_block_1');
}
/**
* Tests that ViewsBlock::build() produces the right output with title tokens.
*
* @see \Drupal\views\Plugin\Block::build()
*/
public function testBuildWithTitleToken() {
$view = Views::getView('test_view_block');
$view->setDisplay();
// Set the title to the 'name' field in the first row.
$view->display_handler->setOption('title', '{{ name }}');
$view->save();
$plugin_definition = [
'provider' => 'views',
];
$plugin_id = 'views_block:test_view_block-block_1';
$views_block = ViewsBlock::create($this->container, [], $plugin_id, $plugin_definition);
$build = $views_block->build();
$this->assertEquals('George', $build['#title']['#markup']);
}
/**
* Tests ViewsBlock::build() with a title override.
*
* @see \Drupal\views\Plugin\Block::build()
*/
public function testBuildWithTitleOverride() {
$view = Views::getView('test_view_block');
$view->setDisplay();
// Add a fixed argument that sets a title and save the view.
$view->displayHandlers->get('default')->overrideOption('arguments', array(
'name' => array(
'default_action' => 'default',
'title_enable' => TRUE,
'title' => 'Overridden title',
'default_argument_type' => 'fixed',
'default_argument_options' => [
'argument' => 'fixed'
],
'validate' => array(
'type' => 'none',
'fail' => 'not found',
),
'id' => 'name',
'table' => 'views_test_data',
'field' => 'name',
'plugin_id' => 'string',
)
));
$view->save();
$plugin_definition = [
'provider' => 'views',
];
$plugin_id = 'views_block:test_view_block-block_1';
$views_block = ViewsBlock::create($this->container, [], $plugin_id, $plugin_definition);
$build = $views_block->build();
$this->assertEquals('Overridden title', $build['#title']['#markup']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment