diff --git a/src/TwigExtension.php b/src/TwigExtension.php index 6ee73a3..fb80467 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -45,6 +45,7 @@ class TwigExtension extends \Twig_Extension { new \Twig_SimpleFunction('drupal_title', [$this, 'drupalTitle']), new \Twig_SimpleFunction('drupal_url', [$this, 'drupalUrl']), new \Twig_SimpleFunction('drupal_link', [$this, 'drupalLink']), + new \Twig_SimpleFunction('drupal_messages', [$this, 'drupalMessages']), ]; } @@ -507,6 +508,13 @@ class TwigExtension extends \Twig_Extension { } } + /** + * Displays status messages. + */ + public function drupalMessages() { + return ['#type' => 'status_messages']; + } + /** * Replaces all tokens in a given string with appropriate values. * diff --git a/tests/src/Functional/TwigTweakTest.php b/tests/src/Functional/TwigTweakTest.php index 634246b..9cc03e7 100644 --- a/tests/src/Functional/TwigTweakTest.php +++ b/tests/src/Functional/TwigTweakTest.php @@ -195,6 +195,10 @@ class TwigTweakTest extends BrowserTestBase { $xpath = '//div[@class = "tt-link"]'; self::assertEquals($link, trim($this->xpath($xpath)[0]->getHtml())); + // Test status messages. + $xpath = '//div[@class = "tt-messages"]/div[contains(@class, "messages--status") and contains(., "Hello world!")]'; + $this->assertByXpath($xpath); + // Test protected link. $xpath = '//div[@class = "tt-link-access"]'; self::assertEquals('', trim($this->xpath($xpath)[0]->getHtml())); diff --git a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig index b60bfe5..a071ed9 100644 --- a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig +++ b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig @@ -43,6 +43,7 @@