From 4277c7699055ce25f68db5cb712e8ca8b61448a5 Mon Sep 17 00:00:00 2001 From: Chi Date: Wed, 28 Mar 2018 14:52:25 +0500 Subject: [PATCH] Remove drupal_set_message Twig function. --- src/TwigExtension.php | 25 ------------------- tests/src/Functional/TwigTweakTest.php | 5 ---- .../templates/twig-tweak-test.html.twig | 1 - 3 files changed, 31 deletions(-) diff --git a/src/TwigExtension.php b/src/TwigExtension.php index 39ab78d..6ee73a3 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -42,9 +42,6 @@ class TwigExtension extends \Twig_Extension { new \Twig_SimpleFunction('drupal_config', [$this, 'drupalConfig']), new \Twig_SimpleFunction('drupal_dump', [$this, 'drupalDump']), new \Twig_SimpleFunction('dd', [$this, 'drupalDump']), - // Wrap drupal_set_message() because it returns some value which is not - // suitable for Twig template. - new \Twig_SimpleFunction('drupal_set_message', [$this, 'drupalSetMessage']), new \Twig_SimpleFunction('drupal_title', [$this, 'drupalTitle']), new \Twig_SimpleFunction('drupal_url', [$this, 'drupalUrl']), new \Twig_SimpleFunction('drupal_link', [$this, 'drupalLink']), @@ -445,28 +442,6 @@ class TwigExtension extends \Twig_Extension { $this->drupalDump($var); } - /** - * Sets a message to display to the user. - * - * @param string|\Drupal\Component\Render\MarkupInterface $message - * (optional) The translated message to be displayed to the user. - * @param string $type - * (optional) The message's type. Defaults to 'status'. - * @param bool $repeat - * (optional) If this is FALSE and the message is already set, then the - * message will not be repeated. Defaults to FALSE. - * - * @return array - * A render array to disable caching. - * - * @see drupal_set_message() - */ - public function drupalSetMessage($message = NULL, $type = 'status', $repeat = FALSE) { - drupal_set_message($message, $type, $repeat); - $build['#cache']['max-age'] = 0; - return $build; - } - /** * Returns a title for the current route. * diff --git a/tests/src/Functional/TwigTweakTest.php b/tests/src/Functional/TwigTweakTest.php index 0af16cf..634246b 100644 --- a/tests/src/Functional/TwigTweakTest.php +++ b/tests/src/Functional/TwigTweakTest.php @@ -104,7 +104,6 @@ class TwigTweakTest extends BrowserTestBase { // Test region. $xpath = '//div[@class = "tt-region"]/div[@class = "region region-sidebar-first"]'; $xpath .= '/div[contains(@class, "block-page-title-block") and h1[@class="page-title" and text() = "Log in"]]'; - $xpath .= '/following-sibling::div[@class="messages messages--warning" and contains(., "Hi!")]'; $xpath .= '/following-sibling::div[contains(@class, "block-system-powered-by-block")]/span[. = "Powered by Drupal"]'; $this->assertByXpath($xpath); @@ -181,10 +180,6 @@ class TwigTweakTest extends BrowserTestBase { $xpath = '//div[@class = "tt-config" and text() = "Anonymous"]'; $this->assertByXpath($xpath); - // Test status message. - $xpath = '//div[@class = "messages messages--warning" and contains(., "Hi!")]'; - $this->assertByXpath($xpath); - // Test page title. $xpath = '//div[@class = "tt-title" and text() = "Beta"]'; $this->assertByXpath($xpath); 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 34779da..b60bfe5 100644 --- a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig +++ b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig @@ -40,7 +40,6 @@
{{ drupal_token('site:name') }}
{{ drupal_token('node:title', {'node': node}) }}
{{ drupal_config('user.settings', 'anonymous') }}
-
{{ drupal_set_message('Hi!', 'warning') }}
{{ drupal_title() }}
{{ drupal_url('node/1', {absolute: true}) }}