Commit 6b489d5d authored by catch's avatar catch

Issue #2853509 by alexpott, xjm, nod_, dmsmidt, dawehner, catch, graber: Don't...

Issue #2853509 by alexpott, xjm, nod_, dmsmidt, dawehner, catch, graber: Don't render status messages if there are no messages but also include their assets if there might be
parent 12ac3a61
......@@ -73,17 +73,22 @@ public static function generatePlaceholder(array $element) {
* @see drupal_get_messages()
*/
public static function renderMessages($type) {
// Render the messages.
return [
'#theme' => 'status_messages',
// @todo Improve when https://www.drupal.org/node/2278383 lands.
'#message_list' => drupal_get_messages($type),
'#status_headings' => [
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
],
];
$render = [];
$messages = drupal_get_messages($type);
if ($messages) {
// Render the messages.
$render = [
'#theme' => 'status_messages',
// @todo Improve when https://www.drupal.org/node/2278383 lands.
'#message_list' => $messages,
'#status_headings' => [
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
],
];
}
return $render;
}
}
......@@ -9,7 +9,6 @@
use Drupal\big_pipe\Render\BigPipeMarkup;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -87,34 +86,15 @@ public static function cases(ContainerInterface $container = NULL, AccountInterf
];
if ($container && $user) {
$status_messages->embeddedAjaxResponseCommands = [
[
'command' => 'settings',
'settings' => [
'ajaxPageState' => [
'theme' => 'classy',
'libraries' => 'big_pipe/big_pipe,classy/base,classy/messages,core/drupal.active-link,core/html5shiv,core/normalize,system/base',
],
'pluralDelimiter' => PluralTranslatableMarkup::DELIMITER,
'user' => [
'uid' => '1',
'permissionsHash' => $container->get('user_permissions_hash_generator')->generate($user),
],
],
'merge' => TRUE,
],
[
'command' => 'add_css',
'data' => '<link rel="stylesheet" href="' . base_path() . 'core/themes/classy/css/components/messages.css?' . $container->get('state')->get('system.css_js_query_string') . '" media="all" />' . "\n"
],
[
'command' => 'insert',
'method' => 'replaceWith',
'selector' => '[data-big-pipe-placeholder-id="callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&args%5B0%5D&token=_HAdUpwWmet0TOTe2PSiJuMntExoshbm1kh2wQzzzAA"]',
'data' => "\n" . ' <div role="contentinfo" aria-label="Status message" class="messages messages--status">' . "\n" . ' <h2 class="visually-hidden">Status message</h2>' . "\n" . ' Hello from BigPipe!' . "\n" . ' </div>' . "\n ",
'data' => ' <div role="contentinfo" aria-label="Status message" class="messages messages--status">' . "\n" . ' <h2 class="visually-hidden">Status message</h2>' . "\n" . ' Hello from BigPipe!' . "\n" . ' </div>' . "\n ",
'settings' => NULL,
],
];
$status_messages->embeddedHtmlResponse = '<link rel="stylesheet" href="' . base_path() . 'core/themes/classy/css/components/messages.css?' . $container->get('state')->get('system.css_js_query_string') . '" media="all" />' . "\n" . "\n" . ' <div role="contentinfo" aria-label="Status message" class="messages messages--status">' . "\n" . ' <h2 class="visually-hidden">Status message</h2>' . "\n" . ' Hello from BigPipe!' . "\n" . ' </div>' . "\n \n";
$status_messages->embeddedHtmlResponse = '<div role="contentinfo" aria-label="Status message" class="messages messages--status">' . "\n" . ' <h2 class="visually-hidden">Status message</h2>' . "\n" . ' Hello from BigPipe!' . "\n" . ' </div>' . "\n \n";
}
......
......@@ -65,6 +65,14 @@ function system_post_update_hashes_clear_cache() {
function system_post_update_timestamp_plugins() {
// Empty post-update hook.
}
/**
* Clear caches to ensure Classy's message library is always added.
*/
function system_post_update_classy_message_library() {
// Empty post-update hook.
}
/**
* Force field type plugin definitions to be cleared.
*
......
......@@ -90,13 +90,13 @@ public function testChanges() {
$active_theme = $this->themeManager->getActiveTheme();
// Make sure we are not testing the wrong theme.
$this->assertEqual('test_theme', $active_theme->getName());
$this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
$this->assertEqual(['classy/base', 'classy/messages', 'core/normalize', 'test_theme/global-styling'], $active_theme->getLibraries());
// @see theme_test_system_info_alter()
$this->state->set('theme_test.modify_info_files', TRUE);
drupal_flush_all_caches();
$active_theme = $this->themeManager->getActiveTheme();
$this->assertEqual(['classy/base', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());
$this->assertEqual(['classy/base', 'classy/messages', 'core/normalize', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries());
}
}
<?php
namespace Drupal\FunctionalTests\Theme;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the Bartik theme.
*
* @group bartik
*/
class BartikTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->assertTrue($this->container->get('theme_installer')->install(['bartik']));
$this->container->get('config.factory')
->getEditable('system.theme')
->set('default', 'bartik')
->save();
}
/**
* Tests that the Bartik theme always adds its message CSS and Classy's.
*
* @see bartik.libraries.yml
* @see classy.info.yml
*/
public function testRegressionMissingMessagesCss() {
$this->drupalGet('');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('bartik/css/components/messages.css');
$this->assertSession()->responseContains('classy/css/components/messages.css');
}
}
<?php
namespace Drupal\FunctionalTests\Theme;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the classy theme.
*
* @group classy
*/
class ClassyTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->assertTrue($this->container->get('theme_installer')->install(['classy']));
$this->container->get('config.factory')
->getEditable('system.theme')
->set('default', 'classy')
->save();
}
/**
* Tests that the Classy theme always adds its message CSS.
*
* @see classy.info.yml
*/
public function testRegressionMissingMessagesCss() {
$this->drupalGet('');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->responseContains('classy/css/components/messages.css');
}
}
......@@ -8,6 +8,7 @@ hidden: true
libraries:
- classy/base
- classy/messages
- core/normalize
libraries-extend:
......
......@@ -21,7 +21,6 @@
* - class: HTML classes.
*/
#}
{{ attach_library('classy/messages') }}
{% block messages %}
{% for type, messages in message_list %}
{%
......
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