From 22e77a0fb432718ebb3f5af100259ddf6e4a0645 Mon Sep 17 00:00:00 2001
From: Brian Canini <canini.16@osu.edu>
Date: Mon, 15 Jun 2020 13:33:33 -0400
Subject: [PATCH] Updating drupal/twig_tweak (2.5.0 => 2.6.0)

---
 composer.json                                 |   2 +-
 composer.lock                                 |  26 ++-
 vendor/composer/installed.json                |  26 ++-
 web/modules/twig_tweak/composer.json          |   3 +-
 web/modules/twig_tweak/src/TwigExtension.php  | 166 ++++++++++++++----
 .../tests/src/Functional/TwigTweakTest.php    |  22 ++-
 .../templates/twig-tweak-test.html.twig       |   8 +
 .../twig_tweak_test/twig_tweak_test.info.yml  |   6 +-
 web/modules/twig_tweak/twig_tweak.info.yml    |   6 +-
 9 files changed, 189 insertions(+), 76 deletions(-)

diff --git a/composer.json b/composer.json
index bd102c444c..c4f081c77d 100644
--- a/composer.json
+++ b/composer.json
@@ -169,7 +169,7 @@
         "drupal/superfish": "1.2",
         "drupal/svg_image": "1.13",
         "drupal/token": "1.5",
-        "drupal/twig_tweak": "2.5",
+        "drupal/twig_tweak": "2.6",
         "drupal/twitter_block": "3.0-alpha0",
         "drupal/userprotect": "1.0",
         "drupal/video_embed_field": "2.2",
diff --git a/composer.lock b/composer.lock
index c89ad298c9..331208f3ca 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "975a2be1ac89395236d7a70f1ba19e36",
+    "content-hash": "2837b524bdf33fdce01ba4dc3b6277aa",
     "packages": [
         {
             "name": "alchemy/zippy",
@@ -7711,32 +7711,30 @@
         },
         {
             "name": "drupal/twig_tweak",
-            "version": "2.5.0",
+            "version": "2.6.0",
             "source": {
                 "type": "git",
                 "url": "https://git.drupalcode.org/project/twig_tweak.git",
-                "reference": "8.x-2.5"
+                "reference": "8.x-2.6"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://ftp.drupal.org/files/projects/twig_tweak-8.x-2.5.zip",
-                "reference": "8.x-2.5",
-                "shasum": "077e193192d85706f5c5afc7575ba07b41499f79"
+                "url": "https://ftp.drupal.org/files/projects/twig_tweak-8.x-2.6.zip",
+                "reference": "8.x-2.6",
+                "shasum": "a877de315bbf8603f146b55e7ca345d8fe70e234"
             },
             "require": {
-                "drupal/core": "^8.7 || ^9.0"
+                "drupal/core": "^8.7 || ^9.0",
+                "twig/twig": "^1.41 || ^2.12"
             },
             "suggest": {
                 "symfony/var-dumper": "Better dump() function for debugging Twig variables"
             },
             "type": "drupal-module",
             "extra": {
-                "branch-alias": {
-                    "dev-2.x": "2.x-dev"
-                },
                 "drupal": {
-                    "version": "8.x-2.5",
-                    "datestamp": "1583937566",
+                    "version": "8.x-2.6",
+                    "datestamp": "1589992479",
                     "security-coverage": {
                         "status": "covered",
                         "message": "Covered by Drupal's security advisory policy"
@@ -8823,12 +8821,12 @@
             "version": "0.9.1",
             "source": {
                 "type": "git",
-                "url": "https://github.com/njh/easyrdf.git",
+                "url": "https://github.com/easyrdf/easyrdf.git",
                 "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/njh/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566",
+                "url": "https://api.github.com/repos/easyrdf/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566",
                 "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566",
                 "shasum": ""
             },
diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json
index 3454a15b23..8c1f81906b 100644
--- a/vendor/composer/installed.json
+++ b/vendor/composer/installed.json
@@ -7949,33 +7949,31 @@
     },
     {
         "name": "drupal/twig_tweak",
-        "version": "2.5.0",
-        "version_normalized": "2.5.0.0",
+        "version": "2.6.0",
+        "version_normalized": "2.6.0.0",
         "source": {
             "type": "git",
             "url": "https://git.drupalcode.org/project/twig_tweak.git",
-            "reference": "8.x-2.5"
+            "reference": "8.x-2.6"
         },
         "dist": {
             "type": "zip",
-            "url": "https://ftp.drupal.org/files/projects/twig_tweak-8.x-2.5.zip",
-            "reference": "8.x-2.5",
-            "shasum": "077e193192d85706f5c5afc7575ba07b41499f79"
+            "url": "https://ftp.drupal.org/files/projects/twig_tweak-8.x-2.6.zip",
+            "reference": "8.x-2.6",
+            "shasum": "a877de315bbf8603f146b55e7ca345d8fe70e234"
         },
         "require": {
-            "drupal/core": "^8.7 || ^9.0"
+            "drupal/core": "^8.7 || ^9.0",
+            "twig/twig": "^1.41 || ^2.12"
         },
         "suggest": {
             "symfony/var-dumper": "Better dump() function for debugging Twig variables"
         },
         "type": "drupal-module",
         "extra": {
-            "branch-alias": {
-                "dev-2.x": "2.x-dev"
-            },
             "drupal": {
-                "version": "8.x-2.5",
-                "datestamp": "1583937566",
+                "version": "8.x-2.6",
+                "datestamp": "1589992479",
                 "security-coverage": {
                     "status": "covered",
                     "message": "Covered by Drupal's security advisory policy"
@@ -9096,12 +9094,12 @@
         "version_normalized": "0.9.1.0",
         "source": {
             "type": "git",
-            "url": "https://github.com/njh/easyrdf.git",
+            "url": "https://github.com/easyrdf/easyrdf.git",
             "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566"
         },
         "dist": {
             "type": "zip",
-            "url": "https://api.github.com/repos/njh/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566",
+            "url": "https://api.github.com/repos/easyrdf/easyrdf/zipball/acd09dfe0555fbcfa254291e433c45fdd4652566",
             "reference": "acd09dfe0555fbcfa254291e433c45fdd4652566",
             "shasum": ""
         },
diff --git a/web/modules/twig_tweak/composer.json b/web/modules/twig_tweak/composer.json
index a32559b875..3b92f8121a 100644
--- a/web/modules/twig_tweak/composer.json
+++ b/web/modules/twig_tweak/composer.json
@@ -10,7 +10,8 @@
         "source": "https://git.drupalcode.org/project/twig_tweak"
     },
     "require": {
-        "drupal/core": "^8.7 || ^9.0"
+        "drupal/core": "^8.7 || ^9.0",
+        "twig/twig": "^1.41 || ^2.12"
     },
     "suggest": {
         "symfony/var-dumper": "Better dump() function for debugging Twig variables"
diff --git a/web/modules/twig_tweak/src/TwigExtension.php b/web/modules/twig_tweak/src/TwigExtension.php
index 5001459eed..0c04dbeb84 100644
--- a/web/modules/twig_tweak/src/TwigExtension.php
+++ b/web/modules/twig_tweak/src/TwigExtension.php
@@ -26,13 +26,16 @@
 use Drupal\media\MediaInterface;
 use Drupal\media\Plugin\media\Source\OEmbedInterface;
 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFilter;
+use Twig\TwigFunction;
 
 /**
  * Twig extension with some useful functions and filters.
  *
  * Dependencies are not injected for performance reason.
  */
-class TwigExtension extends \Twig_Extension {
+class TwigExtension extends AbstractExtension {
 
   /**
    * {@inheritdoc}
@@ -47,14 +50,14 @@ public function getFunctions() {
       // @code
       //   {{ drupal_view('who_s_new', 'block_1') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_view', 'views_embed_view'),
+      new TwigFunction('drupal_view', 'views_embed_view'),
 
       // - Drupal View Result -
       //
       // @code
       //   {{ drupal_view('who_s_new', 'block_1') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_view_result', 'views_get_view_result'),
+      new TwigFunction('drupal_view_result', 'views_get_view_result'),
 
       // - Drupal Block -
       //
@@ -76,7 +79,7 @@ public function getFunctions() {
       // @endcode
       //
       // @see https://www.drupal.org/node/2964457#block-plugin
-      new \Twig_SimpleFunction('drupal_block', [$this, 'drupalBlock']),
+      new TwigFunction('drupal_block', [$this, 'drupalBlock']),
 
       // - Drupal Region -
       //
@@ -87,7 +90,7 @@ public function getFunctions() {
       //   {# Print 'Sidebar First' region of Bartik theme. #}
       //   {{ drupal_region('sidebar_first', 'bartik') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_region', [$this, 'drupalRegion']),
+      new TwigFunction('drupal_region', [$this, 'drupalRegion']),
 
       // - Drupal Entity -
       //
@@ -102,7 +105,7 @@ public function getFunctions() {
       //   {# admin/structure/block page. #}
       //   {{ drupal_entity('block', 'bartik_branding', check_access=false) }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_entity', [$this, 'drupalEntity']),
+      new TwigFunction('drupal_entity', [$this, 'drupalEntity']),
 
       // - Drupal Entity Form -
       //
@@ -116,7 +119,7 @@ public function getFunctions() {
       //   {# Print user register form. #}
       //   {{ drupal_entity_form('user', NULL, 'register', check_access=false) }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_entity_form', [$this, 'drupalEntityForm']),
+      new TwigFunction('drupal_entity_form', [$this, 'drupalEntityForm']),
 
       // - Drupal Field -
       //
@@ -125,21 +128,21 @@ public function getFunctions() {
       //   {{ drupal_field('field_image', 'node', 1, 'teaser') }}
       //   {{ drupal_field('field_image', 'node', 1, {type: 'image_url', settings: {image_style: 'large'}}) }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_field', [$this, 'drupalField']),
+      new TwigFunction('drupal_field', [$this, 'drupalField']),
 
       // - Drupal Menu -
       //
       // @code
       //   {{ drupal_menu('main') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_menu', [$this, 'drupalMenu']),
+      new TwigFunction('drupal_menu', [$this, 'drupalMenu']),
 
       // - Drupal Form -
       //
       // @code
       //   {{ drupal_form('Drupal\\search\\Form\\SearchBlockForm') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_form', [$this, 'drupalForm']),
+      new TwigFunction('drupal_form', [$this, 'drupalForm']),
 
       // - Drupal Image -
       //
@@ -159,21 +162,21 @@ public function getFunctions() {
       //   {# Render responsive image. #}
       //   {{ drupal_image('public://ocean.jpg', 'wide', responsive=true) }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_image', [$this, 'drupalImage']),
+      new TwigFunction('drupal_image', [$this, 'drupalImage']),
 
       // - Drupal Token -
       //
       // @code
       //   {{ drupal_token('site:name') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_token', [$this, 'drupalToken']),
+      new TwigFunction('drupal_token', [$this, 'drupalToken']),
 
       // - Drupal Config -
       //
       // @code
       //   {{ drupal_config('system.site', 'name') }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_config', [$this, 'drupalConfig']),
+      new TwigFunction('drupal_config', [$this, 'drupalConfig']),
 
       // - Drupal Dump -
       //
@@ -187,11 +190,11 @@ public function getFunctions() {
       //   {# Dump all available variables for the current template. #}
       //   {{ dd() }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_dump', [$this, 'drupalDump'], $context_options),
-      new \Twig_SimpleFunction('dd', [$this, 'drupalDump'], $context_options),
+      new TwigFunction('drupal_dump', [$this, 'drupalDump'], $context_options),
+      new TwigFunction('dd', [$this, 'drupalDump'], $context_options),
 
       // - Drupal Title -
-      new \Twig_SimpleFunction('drupal_title', [$this, 'drupalTitle']),
+      new TwigFunction('drupal_title', [$this, 'drupalTitle']),
 
       // - Drupal URL -
       //
@@ -202,7 +205,7 @@ public function getFunctions() {
       //   {# Complex URL. #}
       //   {{ drupal_url('node/1', {query: {foo: 'bar'}, fragment: 'example', absolute: true}) }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_url', [$this, 'drupalUrl']),
+      new TwigFunction('drupal_url', [$this, 'drupalUrl']),
 
       // - Drupal Link -
       //
@@ -213,16 +216,16 @@ public function getFunctions() {
       //   {# This link will only be shown for privileged users. #}
       //   {{ drupal_link('Example'|t, '/admin', check_access=true) }}
       // @endcode
-      new \Twig_SimpleFunction('drupal_link', [$this, 'drupalLink']),
+      new TwigFunction('drupal_link', [$this, 'drupalLink']),
 
       // - Drupal Messages -
-      new \Twig_SimpleFunction('drupal_messages', [$this, 'drupalMessages']),
+      new TwigFunction('drupal_messages', [$this, 'drupalMessages']),
 
       // - Drupal Breadcrumb -
-      new \Twig_SimpleFunction('drupal_breadcrumb', [$this, 'drupalBreadcrumb']),
+      new TwigFunction('drupal_breadcrumb', [$this, 'drupalBreadcrumb']),
 
       // - Drupal Breakpoint -
-      new \Twig_SimpleFunction('drupal_breakpoint', [$this, 'drupalBreakpoint'], $all_options),
+      new TwigFunction('drupal_breakpoint', [$this, 'drupalBreakpoint'], $all_options),
 
       // - Contextual Links -
       //
@@ -238,7 +241,7 @@ public function getFunctions() {
       //     {{ content }}
       //   </div>
       // @endcode
-      new \Twig_SimpleFunction('contextual_links', [$this, 'contextualLinks']),
+      new TwigFunction('contextual_links', [$this, 'contextualLinks']),
     ];
   }
 
@@ -260,7 +263,7 @@ public function getFilters() {
       //     <div>[site:slogan]</div>
       //   {% endapply %}
       // @endcode
-      new \Twig_SimpleFilter('token_replace', [$this, 'tokenReplaceFilter']),
+      new TwigFilter('token_replace', [$this, 'tokenReplaceFilter']),
 
       // - Preg Replace -
       //
@@ -270,35 +273,42 @@ public function getFilters() {
       //
       // For simple string interpolation consider using built-in 'replace' or
       // 'format' Twig filters.
-      new \Twig_SimpleFilter('preg_replace', [$this, 'pregReplaceFilter']),
+      new TwigFilter('preg_replace', [$this, 'pregReplaceFilter']),
 
       // - Image Style -
       //
       // @code
       //  {{ 'public://images/ocean.jpg'|image_style('thumbnail') }}
       // @endcode
-      new \Twig_SimpleFilter('image_style', [$this, 'imageStyle']),
+      new TwigFilter('image_style', [$this, 'imageStyle']),
 
       // - Transliterate -
       //
       // @code
       //   {{ 'Привет!'|transliterate }}
       // @endcode
-      new \Twig_SimpleFilter('transliterate', [$this, 'transliterate']),
+      new TwigFilter('transliterate', [$this, 'transliterate']),
 
       // - Check Markup -
       //
       // @code
       //   {{ '<b>bold</b> <strong>strong</strong>'|check_markup('restricted_html') }}
       // @endcode
-      new \Twig_SimpleFilter('check_markup', [$this, 'checkMarkup']),
+      new TwigFilter('check_markup', [$this, 'checkMarkup']),
+
+      // - Format Size -
+      //
+      // @code
+      //   {{ 12345|format_size() }}
+      // @endcode
+      new TwigFilter('format_size', 'format_size'),
 
       // - Truncate -
       //
       // @code
       //   {{ 'Some long text'|truncate(10, true) }}
       // @endcode
-      new \Twig_SimpleFilter('truncate', [$this, 'truncate']),
+      new TwigFilter('truncate', [$this, 'truncate']),
 
       // - View -
       //
@@ -312,7 +322,7 @@ public function getFilters() {
       //   {{ node.field_image|view('teaser') }}
       //   {{ node.field_image|view({settings: {image_style: 'thumbnail'}}) }}
       // @endcode
-      new \Twig_SimpleFilter('view', [$this, 'view']),
+      new TwigFilter('view', [$this, 'view']),
 
       // - With -
       //
@@ -323,7 +333,7 @@ public function getFilters() {
       //   {# Set nested value. #}
       //   {{ content|with(['field_image', '#title'], 'Photo'|t) }}
       // @endcode
-      new \Twig_SimpleFilter('with', [$this, 'with']),
+      new TwigFilter('with', [$this, 'with']),
 
       // - Children -
       //
@@ -334,7 +344,34 @@ public function getFilters() {
       //     {% endfor %}
       //   </ul>
       // @endcode
-      new \Twig_SimpleFilter('children', [$this, 'children']),
+      new TwigFilter('children', [$this, 'children']),
+
+      // - File URI -
+      //
+      // When field item list passed the URI will be extracted from the first
+      // item. In order to get URI of specific item specify its delta explicitly
+      // using array notation.
+      // @code
+      //   {{ node.field_image|file_uri }}
+      //   {{ node.field_image[0]|file_uri }}
+      // @endcode
+      //
+      // Media fields are fully supported including OEmbed resources, in which
+      // case it will return the URL to the resource, similar to the `file_url`
+      // filter.
+      // @code
+      //   {{ node.field_media|file_uri }}
+      // @endcode
+      //
+      // Useful to apply the `image_style` filter to Media fields.
+      // Remember to check whether a URI is actually returned.
+      // @code
+      //   {% set media_uri = node.field_media|file_uri %}
+      //   {% if media_uri is not null %}
+      //     {{ media_uri|image_style('thumbnail') }}
+      //   {% endif %}
+      // @endcode
+      new TwigFilter('file_uri', [$this, 'fileUri']),
 
       // - File URL -
       //
@@ -355,7 +392,7 @@ public function getFilters() {
       // @code
       //   {{ node.field_media|file_url }}
       // @endcode
-      new \Twig_SimpleFilter('file_url', [$this, 'fileUrl']),
+      new TwigFilter('file_url', [$this, 'fileUrl']),
     ];
 
     if (Settings::get('twig_tweak_enable_php_filter')) {
@@ -378,7 +415,7 @@ public function getFilters() {
       // @code
       //   {{ 'now'|date('Y') }}
       // @endcode
-      $filters[] = new \Twig_SimpleFilter('php', [$this, 'phpFilter']);
+      $filters[] = new TwigFilter('php', [$this, 'phpFilter'], ['needs_context' => TRUE]);
     }
     return $filters;
   }
@@ -622,10 +659,9 @@ public function drupalField($field_name, $entity_type, $id = NULL, $view_mode =
     }
 
     if ($entity) {
+      $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $langcode);
       $access = $check_access ? $entity->access('view', NULL, TRUE) : AccessResult::allowed();
       if ($access->isAllowed()) {
-        $entity = \Drupal::service('entity.repository')
-          ->getTranslationFromContext($entity, $langcode);
         if (isset($entity->{$field_name})) {
           $build = $entity->{$field_name}->view($view_mode);
           CacheableMetadata::createFromRenderArray($build)
@@ -1159,6 +1195,55 @@ public function children(array $build, $sort = FALSE) {
     return array_intersect_key($build, array_flip($keys));
   }
 
+  /**
+   * Returns a URI to the file.
+   *
+   * @param object $input
+   *   An object that contains the URI.
+   *
+   * @return string|null
+   *   A URI that may be used to access the file.
+   */
+  public function fileUri($input) {
+    if ($input instanceof EntityReferenceFieldItemListInterface) {
+      $referenced_entities = $input->referencedEntities();
+      if (isset($referenced_entities[0])) {
+        return self::getUriFromEntity($referenced_entities[0]);
+      }
+    }
+    elseif ($input instanceof EntityReferenceItem) {
+      return self::getUriFromEntity($input->entity);
+    }
+    elseif ($input instanceof EntityInterface) {
+      return self::getUriFromEntity($input);
+    }
+  }
+
+  /**
+   * Extracts file URI from content entity.
+   *
+   * @param object $entity
+   *   Entity object that contains information about the file.
+   *
+   * @return string|null
+   *   A URI that may be used to access the file.
+   */
+  private static function getUriFromEntity($entity) {
+    if ($entity instanceof MediaInterface) {
+      $source = $entity->getSource();
+      $value = $source->getSourceFieldValue($entity);
+      if ($source instanceof OEmbedInterface) {
+        return $value;
+      }
+      elseif ($file = File::load($value)) {
+        return $file->getFileUri();
+      }
+    }
+    elseif ($entity instanceof FileInterface) {
+      return $entity->getFileUri();
+    }
+  }
+
   /**
    * Returns a URL path to the file.
    *
@@ -1184,7 +1269,7 @@ public function fileUrl($input) {
   }
 
   /**
-   * Extracts file URL form content entity.
+   * Extracts file URL from content entity.
    *
    * @param object $entity
    *   Entity object that contains information about the file.
@@ -1211,17 +1296,20 @@ private static function getUrlFromEntity($entity) {
   /**
    * Evaluates a string of PHP code.
    *
+   * @param array $context
+   *   Twig context.
    * @param string $code
    *   Valid PHP code to be evaluated.
    *
    * @return mixed
    *   The eval() result.
    */
-  public function phpFilter($code) {
+  public function phpFilter(array $context, $code) {
+    // Make Twig variables available in PHP code.
+    extract($context);
     ob_start();
-    // @codingStandardsIgnoreStart
+    // phpcs:ignore Drupal.Functions.DiscouragedFunctions.Discouraged
     print eval($code);
-    // @codingStandardsIgnoreEnd
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
diff --git a/web/modules/twig_tweak/tests/src/Functional/TwigTweakTest.php b/web/modules/twig_tweak/tests/src/Functional/TwigTweakTest.php
index 0bedf48e0e..085491908d 100644
--- a/web/modules/twig_tweak/tests/src/Functional/TwigTweakTest.php
+++ b/web/modules/twig_tweak/tests/src/Functional/TwigTweakTest.php
@@ -320,6 +320,10 @@ public function testOutput() {
     $xpath = '//div[@class = "tt-check-markup"]';
     self::assertEquals('<b>bold</b> strong', trim($this->xpath($xpath)[0]->getHtml()));
 
+    // -- Format size.
+    $xpath = '//div[@class = "tt-format-size"]';
+    self::assertSame('12.06 KB', $this->xpath($xpath)[0]->getHtml());
+
     // -- Test truncation.
     $xpath = '//div[@class = "tt-truncate" and text() = "Hello…"]';
     $this->assertByXpath($xpath);
@@ -349,12 +353,28 @@ public function testOutput() {
     $xpath = '//div[@class = "tt-field-item-view" and text() = "Beta"]';
     $this->assertByXpath($xpath);
 
+    // -- Test file URI from image field.
+    $this->drupalGet('/node/1');
+    $xpath = '//div[@class = "tt-file-uri-from-image-field" and contains(text(), "public://image-test.png")]';
+    $this->assertByXpath($xpath);
+
+    // -- Test file URI from a specific image field item.
+    $xpath = '//div[@class = "tt-file-uri-from-image-field-delta" and contains(text(), "public://image-test.png")]';
+    $this->assertByXpath($xpath);
+
+    // -- Test file URI from media field.
+    $xpath = '//div[@class = "tt-file-uri-from-media-field" and contains(text(), "public://image-1.png")]';
+    $this->assertByXpath($xpath);
+
+    // -- Test image style from file URI from media field.
+    $xpath = '//div[@class = "tt-image-style-from-file-uri-from-media-field" and contains(text(), "styles/thumbnail/public/image-1.png")]';
+    $this->assertByXpath($xpath);
+
     // -- Test file URL from URI.
     $xpath = '//div[@class = "tt-file-url-from-uri" and contains(text(), "/files/image-test.png")]';
     $this->assertByXpath($xpath);
 
     // -- Test file URL from image field.
-    $this->drupalGet('/node/1');
     $xpath = '//div[@class = "tt-file-url-from-image-field" and contains(text(), "/files/image-test.png")]';
     $this->assertByXpath($xpath);
 
diff --git a/web/modules/twig_tweak/tests/twig_tweak_test/templates/twig-tweak-test.html.twig b/web/modules/twig_tweak/tests/twig_tweak_test/templates/twig-tweak-test.html.twig
index 847ced89f3..49df8ef9c0 100644
--- a/web/modules/twig_tweak/tests/twig_tweak_test/templates/twig-tweak-test.html.twig
+++ b/web/modules/twig_tweak/tests/twig_tweak_test/templates/twig-tweak-test.html.twig
@@ -58,6 +58,7 @@
   <div class="tt-image-style">{{ 'public://images/ocean.jpg' | image_style('thumbnail') }}</div>
   <div class="tt-transliterate">{{ 'Привет!' | transliterate('ru') }}</div>
   <div class="tt-check-markup">{{ '<b>bold</b> <strong>strong</strong>' | check_markup('twig_tweak_test') }}</div>
+  <div class="tt-format-size">{{ 12345|format_size() }}</div>
   <div class="tt-truncate">{{ 'Hello world!'|truncate(10, true, true) }}</div>
   <div class="tt-with">{{ {'#markup':'Example'}|with('#prefix', '<b>')|with('#suffix', '</b>') }}</div>
   <div class="tt-with-nested">{{ {alpha: {beta: {gamma: 123}}}|with(['alpha', 'beta', 'gamma'], 456)|json_encode|replace({'"':''}) }}</div>
@@ -78,6 +79,13 @@
   <div class="tt-node-view">{{ node|view }}</div>
   <div class="tt-field-list-view">{{ node.title|view }}</div>
   <div class="tt-field-item-view">{{ node.title[0]|view }}</div>
+  <div class="tt-file-uri-from-image-field">{{ node.field_image|file_uri }}</div>
+  <div class="tt-file-uri-from-image-field-delta">{{ node.field_image[0]|file_uri }}</div>
+  {% set media_uri = node.field_media|file_uri %}
+  <div class="tt-file-uri-from-media-field">{{ media_uri }}</div>
+  {% if media_uri is not null %}
+    <div class="tt-image-style-from-file-uri-from-media-field">{{ media_uri|image_style('thumbnail') }}</div>
+  {% endif %}
   <div class="tt-file-url-from-uri">{{ 'public://image-test.png'|file_url }}</div>
   <div class="tt-file-url-from-image-field">{{ node.field_image|file_url }}</div>
   <div class="tt-file-url-from-image-field-delta">{{ node.field_image[0]|file_url }}</div>
diff --git a/web/modules/twig_tweak/tests/twig_tweak_test/twig_tweak_test.info.yml b/web/modules/twig_tweak/tests/twig_tweak_test/twig_tweak_test.info.yml
index d7ab52c282..86c7d30844 100644
--- a/web/modules/twig_tweak/tests/twig_tweak_test/twig_tweak_test.info.yml
+++ b/web/modules/twig_tweak/tests/twig_tweak_test/twig_tweak_test.info.yml
@@ -10,7 +10,7 @@ dependencies:
   - drupal:media
   - drupal:twig_tweak
 
-# Information added by Drupal.org packaging script on 2020-03-11
-version: '8.x-2.5'
+# Information added by Drupal.org packaging script on 2020-05-20
+version: '8.x-2.6'
 project: 'twig_tweak'
-datestamp: 1583908077
+datestamp: 1589992481
diff --git a/web/modules/twig_tweak/twig_tweak.info.yml b/web/modules/twig_tweak/twig_tweak.info.yml
index 2fac4a5aa8..ac1683e194 100644
--- a/web/modules/twig_tweak/twig_tweak.info.yml
+++ b/web/modules/twig_tweak/twig_tweak.info.yml
@@ -6,7 +6,7 @@ core_version_requirement: ^8 || ^9
 dependencies:
   - drupal:system (>=8.7)
 
-# Information added by Drupal.org packaging script on 2020-03-11
-version: '8.x-2.5'
+# Information added by Drupal.org packaging script on 2020-05-20
+version: '8.x-2.6'
 project: 'twig_tweak'
-datestamp: 1583908077
+datestamp: 1589992481
-- 
GitLab