Browse Source

Code cleanup.

merge-requests/4/head
Chi 7 years ago
parent
commit
6a024c5df3
  1. 10
      src/TwigExtension.php
  2. 6
      tests/src/Functional/TwigTweakTest.php

10
src/TwigExtension.php

@ -582,8 +582,8 @@ class TwigExtension extends \Twig_Extension {
* *
* @param mixed $object * @param mixed $object
* The object to build a render array from. * The object to build a render array from.
* @param string $view_mode * @param string|array $display_options
* (optional) The view mode that should be used to render the field. * Can be either the name of a view mode, or an array of display settings.
* @param string $langcode * @param string $langcode
* (optional) For which language the entity should be rendered, defaults to * (optional) For which language the entity should be rendered, defaults to
* the current content language. * the current content language.
@ -593,14 +593,14 @@ class TwigExtension extends \Twig_Extension {
* @return array * @return array
* A render array to represent the object. * A render array to represent the object.
*/ */
public function view($object, $view_mode = 'default', $langcode = NULL, $check_access = TRUE) { public function view($object, $display_options = 'default', $langcode = NULL, $check_access = TRUE) {
if ($object instanceof FieldItemListInterface || $object instanceof FieldItemInterface) { if ($object instanceof FieldItemListInterface || $object instanceof FieldItemInterface) {
return $object->view($view_mode); return $object->view($display_options);
} }
elseif ($object instanceof EntityInterface && (!$check_access || $object->access('view'))) { elseif ($object instanceof EntityInterface && (!$check_access || $object->access('view'))) {
return \Drupal::entityTypeManager() return \Drupal::entityTypeManager()
->getViewBuilder($object->getEntityTypeId()) ->getViewBuilder($object->getEntityTypeId())
->view($object, $view_mode, $langcode); ->view($object, $display_options, $langcode);
} }
} }

6
tests/src/Functional/TwigTweakTest.php

@ -190,11 +190,11 @@ class TwigTweakTest extends BrowserTestBase {
$url = Url::fromUserInput('/node/1/edit', ['absolute' => TRUE]); $url = Url::fromUserInput('/node/1/edit', ['absolute' => TRUE]);
$link = Link::fromTextAndUrl('Edit', $url)->toString(); $link = Link::fromTextAndUrl('Edit', $url)->toString();
$xpath = '//div[@class = "tt-link"]'; $xpath = '//div[@class = "tt-link"]';
$this->assertEquals($link, trim($this->xpath($xpath)[0]->getHtml())); self::assertEquals($link, trim($this->xpath($xpath)[0]->getHtml()));
// Test protected link. // Test protected link.
$xpath = '//div[@class = "tt-link-access"]'; $xpath = '//div[@class = "tt-link-access"]';
$this->assertEquals('', trim($this->xpath($xpath)[0]->getHtml())); self::assertEquals('', trim($this->xpath($xpath)[0]->getHtml()));
// Test token replacement. // Test token replacement.
$xpath = '//div[@class = "tt-token-replace" and text() = "Site name: Drupal"]'; $xpath = '//div[@class = "tt-token-replace" and text() = "Site name: Drupal"]';
@ -214,7 +214,7 @@ class TwigTweakTest extends BrowserTestBase {
// Test text format. // Test text format.
$xpath = '//div[@class = "tt-check-markup"]'; $xpath = '//div[@class = "tt-check-markup"]';
$this->assertEquals('<b>bold</b> strong', trim($this->xpath($xpath)[0]->getHtml())); self::assertEquals('<b>bold</b> strong', trim($this->xpath($xpath)[0]->getHtml()));
// Test node view. // Test node view.
$xpath = '//div[@class = "tt-node-view"]/article[contains(@class, "node--view-mode-default")]/h2[a/span[text() = "Beta"]]'; $xpath = '//div[@class = "tt-node-view"]/article[contains(@class, "node--view-mode-default")]/h2[a/span[text() = "Beta"]]';

Loading…
Cancel
Save