Revert "Issue #2361481 by Lendude, evanjenkins, xjm, dawehner, Zekvyrin: Argument validations doesn't set the block title anymore"
This reverts commit 0d71430c4f
.
8.3.x
parent
d3ba24ab3f
commit
113f7b51cc
|
@ -27,6 +27,11 @@ class ViewsBlock extends ViewsBlockBase {
|
||||||
// entry for the view output by passing FALSE, because we're going to cache
|
// entry for the view output by passing FALSE, because we're going to cache
|
||||||
// the whole block instead.
|
// the whole block instead.
|
||||||
if ($output = $this->view->buildRenderable($this->displayID, [], FALSE)) {
|
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
|
// Before returning the block output, convert it to a renderable array
|
||||||
// with contextual links.
|
// with contextual links.
|
||||||
$this->addContextualLinks($output);
|
$this->addContextualLinks($output);
|
||||||
|
@ -36,11 +41,6 @@ class ViewsBlock extends ViewsBlockBase {
|
||||||
// #pre_render callback has already been applied.
|
// #pre_render callback has already been applied.
|
||||||
$output = View::preRenderViewElement($output);
|
$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
|
// 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
|
// 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
|
// render system knows the reasons (cache contexts & tags) why this Views
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace Drupal\Tests\views\Kernel\Plugin;
|
||||||
use Drupal\views\Plugin\Block\ViewsBlock;
|
use Drupal\views\Plugin\Block\ViewsBlock;
|
||||||
use Drupal\views\Tests\ViewTestData;
|
use Drupal\views\Tests\ViewTestData;
|
||||||
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
|
||||||
use Drupal\views\Views;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests native behaviors of the block views plugin.
|
* Tests native behaviors of the block views plugin.
|
||||||
|
@ -52,68 +51,4 @@ class ViewsBlockTest extends ViewsKernelTestBase {
|
||||||
$this->assertEqual($views_block->getMachineNameSuggestion(), 'views_block__test_view_block_block_1');
|
$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']);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue