Browse Source

Issue #2925554 by Mookum: Add drupal_view_result() function.

merge-requests/4/head
Chi 7 years ago
parent
commit
147fbd900d
  1. 1
      src/TwigExtension.php
  2. 4
      tests/src/Functional/TwigTweakTest.php
  3. 1
      tests/twig_tweak_test/templates/twig-tweak-test.html.twig

1
src/TwigExtension.php

@ -21,6 +21,7 @@ class TwigExtension extends \Twig_Extension {
public function getFunctions() { public function getFunctions() {
return [ return [
new \Twig_SimpleFunction('drupal_view', 'views_embed_view'), 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_block', [$this, 'drupalBlock']),
new \Twig_SimpleFunction('drupal_region', [$this, 'drupalRegion']), new \Twig_SimpleFunction('drupal_region', [$this, 'drupalRegion']),
new \Twig_SimpleFunction('drupal_entity', [$this, 'drupalEntity']), new \Twig_SimpleFunction('drupal_entity', [$this, 'drupalEntity']),

4
tests/src/Functional/TwigTweakTest.php

@ -65,6 +65,10 @@ class TwigTweakTest extends BrowserTestBase {
$xpath .= '/div[@class = "view-content"]//ul[count(./li) = 1]/li'; $xpath .= '/div[@class = "view-content"]//ul[count(./li) = 1]/li';
$this->assertByXpath($xpath . '//a[contains(@href, "/node/1") and text() = "Alpha"]'); $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. // Test block plugin.
$xpath = '//div[@class = "tt-block"]'; $xpath = '//div[@class = "tt-block"]';
$xpath .= '/img[contains(@src, "/core/themes/classy/logo.svg") and @alt="Home"]'; $xpath .= '/img[contains(@src, "/core/themes/classy/logo.svg") and @alt="Home"]';

1
tests/twig_tweak_test/templates/twig-tweak-test.html.twig

@ -19,6 +19,7 @@
<div class="tt-view-default">{{ drupal_view('twig_tweak_test') }}</div> <div class="tt-view-default">{{ drupal_view('twig_tweak_test') }}</div>
<div class="tt-view-page_1">{{ drupal_view('twig_tweak_test', 'page_1') }}</div> <div class="tt-view-page_1">{{ drupal_view('twig_tweak_test', 'page_1') }}</div>
<div class="tt-view-page_1-with-argument">{{ drupal_view('twig_tweak_test', 'page_1', 1) }}</div> <div class="tt-view-page_1-with-argument">{{ drupal_view('twig_tweak_test', 'page_1', 1) }}</div>
<div class="tt-view-result">{{ drupal_view_result('twig_tweak_test', 'page_1')|length }}</div>
<div class="tt-block">{{ drupal_block('system_branding_block', {use_site_name: false}) }}</div> <div class="tt-block">{{ drupal_block('system_branding_block', {use_site_name: false}) }}</div>
<div class="tt-region">{{ drupal_region('sidebar_first') }}</div> <div class="tt-region">{{ drupal_region('sidebar_first') }}</div>
<div class="tt-entity-default">{{ drupal_entity('node', 1) }}</div> <div class="tt-entity-default">{{ drupal_entity('node', 1) }}</div>

Loading…
Cancel
Save