diff --git a/core/lib/Drupal/Core/Render/Element/StatusMessages.php b/core/lib/Drupal/Core/Render/Element/StatusMessages.php index d16c245..530457f 100644 --- a/core/lib/Drupal/Core/Render/Element/StatusMessages.php +++ b/core/lib/Drupal/Core/Render/Element/StatusMessages.php @@ -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; } } diff --git a/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php index 4637780..7b5c33f 100644 --- a/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php +++ b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php @@ -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; @@ -88,33 +87,14 @@ 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' => '' . "\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" . ' ' . "\n ", + 'data' => ' ' . "\n ", 'settings' => NULL, ], ]; - $status_messages->embeddedHtmlResponse = '' . "\n" . "\n" . ' ' . "\n \n"; + $status_messages->embeddedHtmlResponse = '' . "\n \n"; } diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php index 5ed7ea0..36039df 100644 --- a/core/modules/system/system.post_update.php +++ b/core/modules/system/system.post_update.php @@ -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. * diff --git a/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php b/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php index ee41968..534f614 100644 --- a/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php +++ b/core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php @@ -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()); } } diff --git a/core/tests/Drupal/FunctionalTests/Theme/BartikTest.php b/core/tests/Drupal/FunctionalTests/Theme/BartikTest.php new file mode 100644 index 0000000..0ffd9af --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Theme/BartikTest.php @@ -0,0 +1,42 @@ +assertTrue($this->container->get('theme_installer')->install(['bartik'])); + $this->container->get('config.factory') + ->getEditable('system.theme') + ->set('default', 'bartik') + ->save(); + // Clear the theme registry. + $this->container->set('theme.registry', NULL); + } + + /** + * Tests the Bartik theme always adds classy's and its message CSS. + */ + public function testRegressionMissingMessagesCss() { + $this->drupalGet(''); + $this->assertSession()->statusCodeEquals(200); + // Ensure that Classy's message.css is loaded. + // @see classy.info.yml + $this->assertSession()->responseContains('classy/css/components/messages.css'); + $this->assertSession()->responseContains('bartik/css/components/messages.css'); + } + +} diff --git a/core/tests/Drupal/FunctionalTests/Theme/ClassyTest.php b/core/tests/Drupal/FunctionalTests/Theme/ClassyTest.php new file mode 100644 index 0000000..f4c87b4 --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Theme/ClassyTest.php @@ -0,0 +1,41 @@ +assertTrue($this->container->get('theme_installer')->install(['classy'])); + $this->container->get('config.factory') + ->getEditable('system.theme') + ->set('default', 'classy') + ->save(); + // Clear the theme registry. + $this->container->set('theme.registry', NULL); + } + + /** + * Tests the Classy theme always adds it's message CSS. + */ + public function testRegressionMissingMessagesCss() { + $this->drupalGet(''); + $this->assertSession()->statusCodeEquals(200); + // Ensure that Classy's message.css is loaded. + // @see classy.info.yml + $this->assertSession()->responseContains('classy/css/components/messages.css'); + } + +} diff --git a/core/themes/classy/classy.info.yml b/core/themes/classy/classy.info.yml index 05ef0d7..4685c3f 100644 --- a/core/themes/classy/classy.info.yml +++ b/core/themes/classy/classy.info.yml @@ -8,6 +8,7 @@ hidden: true libraries: - classy/base + - classy/messages - core/normalize libraries-extend: diff --git a/core/themes/classy/templates/misc/status-messages.html.twig b/core/themes/classy/templates/misc/status-messages.html.twig index bc8fd10..282df38 100644 --- a/core/themes/classy/templates/misc/status-messages.html.twig +++ b/core/themes/classy/templates/misc/status-messages.html.twig @@ -21,7 +21,6 @@ * - class: HTML classes. */ #} -{{ attach_library('classy/messages') }} {% block messages %} {% for type, messages in message_list %} {%