Commit 04dd2750 authored by alexpott's avatar alexpott

Issue #2210755 by damiankloip, tim.plunkett: Add an area handler to display drupal_set_messages.

parent e088b8f0
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\area\Messages.
*/
namespace Drupal\views\Plugin\views\area;
/**
* Provides an area for messages.
*
* @ingroup views_area_handlers
*
* @PluginID("messages")
*/
class Messages extends AreaPluginBase {
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
// Set the default to TRUE so it shows on empty pages by default.
$options['empty']['default'] = TRUE;
return $options;
}
/**
* {@inheritdoc}
*/
public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
return array(
'#theme' => 'status_messages',
);
}
return array();
}
}
<?php
/**
* @file
* Contains \Drupal\views\Tests\Plugin\area\MessagesTest.
*/
namespace Drupal\views\Tests\Plugin\area;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\area\Messages;
/**
* Tests the messages area handler
*
* @group Views
* @group Handlers
*
* @coversDefaultClass \Drupal\views\Plugin\views\area\Messages
*/
class MessagesTest extends UnitTestCase {
/**
* The view executable object.
*
* @var \Drupal\views\ViewExecutable
*/
protected $view;
/**
* The message handler.
*
* @var \Drupal\views\Plugin\views\area\Messages
*/
protected $messagesHandler;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Area: Messages',
'description' => 'Tests the Drupal\views\Plugin\views\area\Messages handler.',
'group' => 'Views Handlers',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->messagesHandler = new Messages(array(), 'result', array());
}
/**
* Tests the render method.
*
* @covers ::defineOptions()
* @covers ::render()
*/
public function testRender() {
// The handler is configured to show with empty views by default, so should
// appear.
$this->assertSame(array('#theme' => 'status_messages'), $this->messagesHandler->render());
// Turn empty off, and make sure it isn't rendered.
$this->messagesHandler->options['empty'] = FALSE;
// $empty parameter passed to render will still be FALSE, so should still
// appear.
$this->assertSame(array('#theme' => 'status_messages'), $this->messagesHandler->render());
// Should now be empty as both the empty option and parameter are empty.
$this->assertSame(array(), $this->messagesHandler->render(TRUE));
}
}
......@@ -90,6 +90,14 @@ function views_views_data() {
),
);
$data['views']['messages'] = array(
'title' => t('Messages'),
'help' => t('Displays messages in an area.'),
'area' => array(
'id' => 'messages',
),
);
$data['views']['http_status_code'] = array(
'title' => t('Response status code'),
'help' => t('Alter the HTTP response status code used by this view, mostly helpful for empty results.'),
......
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