Skip to content
Snippets Groups Projects
Commit 493004d4 authored by Damian Lee's avatar Damian Lee Committed by Tim Plunkett
Browse files

Issue #1808542 by damiankloip: Allow area handlers to override the page title...

Issue #1808542 by damiankloip: Allow area handlers to override the page title when used in an empty area.
parent f5289f54
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Definition of Drupal\views\Plugin\views\area\Title.
*/
namespace Drupal\views\Plugin\views\area;
use Drupal\Core\Annotation\Plugin;
/**
* Views area title override handler.
*
* @ingroup views_area_handlers
*
* @Plugin(
* id = "title"
* )
*/
class Title extends AreaPluginBase {
/**
* Overrides Drupal\views\Plugin\views\AreaPluginBase::defineOptions().
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['title'] = array('default' => '', 'translatable' => TRUE);
return $options;
}
/**
* Overrides Drupal\views\Plugin\views\AreaPluginBase::buildOptionsForm().
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Overridden title'),
'#default_value' => $this->options['title'],
'#description' => t('Override the title of this view when it is empty.'),
);
}
/**
* Overrides Drupal\views\Plugin\views\AreaPluginBase::render().
*/
function render($empty = FALSE) {
if (!empty($this->options['title'])) {
$this->view->setTitle(filter_xss_admin($this->options['title']), PASS_THROUGH);
}
return '';
}
}
......@@ -104,4 +104,30 @@ public function testRenderArea() {
$this->assertTrue(strpos($output, $empty_string) !== FALSE);
}
/**
* Tests overriding the view title using the area title handler.
*/
public function testTitleArea() {
$view = views_get_view('frontpage');
$view->initDisplay('page_1');
// Add the title area handler to the empty area.
$view->displayHandlers['page_1']->overrideOption('empty', array(
'title' => array(
'id' => 'title',
'table' => 'views',
'field' => 'title',
'admin_label' => '',
'label' => '',
'empty' => '0',
'title' => 'Overridden title',
),
));
$view->storage->enable();
$this->drupalGet('frontpage');
$this->assertText('Overridden title', 'Overridden title found.');
}
}
......@@ -65,6 +65,14 @@ function views_views_data() {
),
);
$data['views']['title'] = array(
'title' => t('Title override'),
'help' => t('Override the default view title for this view. This is useful to display an alternative title when a view is empty.'),
'area' => array(
'id' => 'title',
),
);
$data['views']['view'] = array(
'title' => t('View area'),
'help' => t('Insert a view inside an area.'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment