Commit 790c021d authored by Cottser's avatar Cottser

Issue #2752413 by danmuzyka, alexpott, jhedstrom: Custom CSS classes added to...

Issue #2752413 by danmuzyka, alexpott, jhedstrom: Custom CSS classes added to status messages print on page as content when using Classy theme or subthemes
parent 00b6a1fe
......@@ -110,7 +110,7 @@ public static function cases(ContainerInterface $container = NULL, AccountInterf
'command' => 'insert',
'method' => 'replaceWith',
'selector' => '[data-big-pipe-placeholder-id="callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&args[0]&token=a8c34b5e"]',
'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 \n",
'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 ",
'settings' => NULL,
],
];
......
......@@ -114,3 +114,10 @@ function _test_theme_twig_php_values() {
),
);
}
/**
* Implements template_preprocess_status_messages().
*/
function twig_theme_test_preprocess_status_messages(&$variables) {
$variables['attributes']['class'][] = 'custom-test-messages-class';
}
<?php
namespace Drupal\Tests\system\Kernel\Render;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the Classy theme.
*
* @group Theme
*/
class ClassyTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('system', 'twig_theme_test');
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
// Use the classy theme.
$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);
}
/**
* Test the classy theme.
*/
function testClassyTheme() {
drupal_set_message('An error occurred', 'error');
drupal_set_message('But then something nice happened');
$messages = array(
'#type' => 'status_messages',
);
$this->render($messages);
$this->assertNoText('custom-test-messages-class', 'The custom class attribute value added in the status messages preprocess function is not displayed as page content.');
}
}
......@@ -51,6 +51,6 @@
{% endif %}
</div>
{# Remove type specific classes. #}
{{ attributes.removeClass(classes) }}
{% set attributes = attributes.removeClass(classes) %}
{% endfor %}
{% endblock messages %}
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