Commit 493004d4 authored by damiankloip's avatar damiankloip Committed by tim.plunkett

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
<?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.'),
......
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