From 147fbd900d68da34c2154b0091fe298c94cc4a06 Mon Sep 17 00:00:00 2001 From: Chi Date: Sat, 25 Nov 2017 14:48:16 +0500 Subject: [PATCH] Issue #2925554 by Mookum: Add drupal_view_result() function. --- src/TwigExtension.php | 1 + tests/src/Functional/TwigTweakTest.php | 4 ++++ tests/twig_tweak_test/templates/twig-tweak-test.html.twig | 1 + 3 files changed, 6 insertions(+) diff --git a/src/TwigExtension.php b/src/TwigExtension.php index a54ee10..830e431 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -21,6 +21,7 @@ class TwigExtension extends \Twig_Extension { public function getFunctions() { return [ new \Twig_SimpleFunction('drupal_view', 'views_embed_view'), + new \Twig_SimpleFunction('drupal_view_result', 'views_get_view_result'), new \Twig_SimpleFunction('drupal_block', [$this, 'drupalBlock']), new \Twig_SimpleFunction('drupal_region', [$this, 'drupalRegion']), new \Twig_SimpleFunction('drupal_entity', [$this, 'drupalEntity']), diff --git a/tests/src/Functional/TwigTweakTest.php b/tests/src/Functional/TwigTweakTest.php index 43bdb2f..17d62df 100644 --- a/tests/src/Functional/TwigTweakTest.php +++ b/tests/src/Functional/TwigTweakTest.php @@ -65,6 +65,10 @@ class TwigTweakTest extends BrowserTestBase { $xpath .= '/div[@class = "view-content"]//ul[count(./li) = 1]/li'; $this->assertByXpath($xpath . '//a[contains(@href, "/node/1") and text() = "Alpha"]'); + // Test view result. + $xpath = '//div[@class = "tt-view-result" and text() = 3]'; + $this->assertByXpath($xpath); + // Test block plugin. $xpath = '//div[@class = "tt-block"]'; $xpath .= '/img[contains(@src, "/core/themes/classy/logo.svg") and @alt="Home"]'; 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 a46539c..ed606a3 100644 --- a/tests/twig_tweak_test/templates/twig-tweak-test.html.twig +++ b/tests/twig_tweak_test/templates/twig-tweak-test.html.twig @@ -19,6 +19,7 @@
{{ drupal_view('twig_tweak_test') }}
{{ drupal_view('twig_tweak_test', 'page_1') }}
{{ drupal_view('twig_tweak_test', 'page_1', 1) }}
+
{{ drupal_view_result('twig_tweak_test', 'page_1')|length }}
{{ drupal_block('system_branding_block', {use_site_name: false}) }}
{{ drupal_region('sidebar_first') }}
{{ drupal_entity('node', 1) }}