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
* The object to build a render array from.
* @param string $view_mode
* (optional) The view mode that should be used to render the field.
* @param string|array $display_options
* Can be either the name of a view mode, or an array of display settings.
* @param string $langcode
* (optional) For which language the entity should be rendered, defaults to
* the current content language.
@ -593,14 +593,14 @@ class TwigExtension extends \Twig_Extension {
* @return array
* 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) {
return $object->view($view_mode);
return $object->view($display_options);
}
elseif ($object instanceof EntityInterface && (!$check_access || $object->access('view'))) {
return \Drupal::entityTypeManager()
->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]);
$link = Link::fromTextAndUrl('Edit', $url)->toString();
$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.
$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.
$xpath = '//div[@class = "tt-token-replace" and text() = "Site name: Drupal"]';
@ -214,7 +214,7 @@ class TwigTweakTest extends BrowserTestBase {
// Test text format.
$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.
$xpath = '//div[@class = "tt-node-view"]/article[contains(@class, "node--view-mode-default")]/h2[a/span[text() = "Beta"]]';

Loading…
Cancel
Save