From 7e18d45eeee54b2c0e8789d91d0f8c2bb9aa63a7 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Thu, 14 Mar 2019 15:31:42 -0500
Subject: [PATCH] Issue #3040210 by Spokje, phenaproxima, shaal, lauriii,
 hctom, a.dmitriiev, xjm, cilefen, eelkeblok: Updating twig/twig to v1.38.2
 (included in Drupal 8.6.11) causes fatal error when embed tags are used in
 templates

---
 .../src/TwigThemeTestController.php           |  7 +++++
 ...ig-theme-test-embed-tag-embedded.html.twig |  1 +
 .../twig_theme_test.embed_tag.html.twig       |  3 ++
 .../twig_theme_test/twig_theme_test.module    |  4 +++
 .../twig_theme_test.routing.yml               |  7 +++++
 .../Functional/Theme/TwigEnvironmentTest.php  | 30 +++++++++++++++++++
 6 files changed, 52 insertions(+)
 create mode 100644 core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig
 create mode 100644 core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig
 create mode 100644 core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php

diff --git a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php
index 1e995c58f754..fcaf319368ad 100644
--- a/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php
+++ b/core/modules/system/tests/modules/twig_theme_test/src/TwigThemeTestController.php
@@ -104,4 +104,11 @@ public function renderable() {
     ];
   }
 
+  /**
+   * Renders for testing the embed tag in a Twig template.
+   */
+  public function embedTagRender() {
+    return ['#theme' => 'twig_theme_test_embed_tag'];
+  }
+
 }
diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig
new file mode 100644
index 000000000000..63d7f477cbb9
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig
@@ -0,0 +1 @@
+This line is from twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig
diff --git a/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig
new file mode 100644
index 000000000000..035c3784e4e7
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_theme_test/templates/twig_theme_test.embed_tag.html.twig
@@ -0,0 +1,3 @@
+{% embed "@twig_theme_test/twig-theme-test-embed-tag-embedded.html.twig" %}
+
+{% endembed %}
diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
index a8b4086203ad..31a1a4693043 100644
--- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
+++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.module
@@ -73,6 +73,10 @@ function twig_theme_test_theme($existing, $type, $theme, $path) {
     ],
     'template' => 'twig_theme_test.renderable',
   ];
+  $items['twig_theme_test_embed_tag'] = [
+    'variables' => [],
+    'template' => 'twig_theme_test.embed_tag',
+  ];
   return $items;
 }
 
diff --git a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml
index df665c346431..e671d70fbbf7 100644
--- a/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml
+++ b/core/modules/system/tests/modules/twig_theme_test/twig_theme_test.routing.yml
@@ -69,3 +69,10 @@ twig_theme_test_renderable:
     _controller: '\Drupal\twig_theme_test\TwigThemeTestController::renderable'
   requirements:
     _access: 'TRUE'
+
+twig_theme_test_embed_tag:
+  path: '/twig-theme-test/embed-tag'
+  defaults:
+    _controller: '\Drupal\twig_theme_test\TwigThemeTestController::embedTagRender'
+  requirements:
+    _access: 'TRUE'
diff --git a/core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php b/core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php
new file mode 100644
index 000000000000..26f47e9068eb
--- /dev/null
+++ b/core/modules/system/tests/src/Functional/Theme/TwigEnvironmentTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Drupal\Tests\system\Functional\Theme;
+
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Tests Twig environment.
+ *
+ * @group Theme
+ */
+class TwigEnvironmentTest extends BrowserTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['twig_theme_test'];
+
+  /**
+   * Tests template class loading with Twig embed.
+   */
+  public function testTwigEmbed() {
+    $assert_session = $this->assertSession();
+    // Test the Twig embed tag.
+    $this->drupalGet('twig-theme-test/embed-tag');
+    $assert_session->statusCodeEquals(200);
+    $assert_session->responseContains('This line is from twig_theme_test/templates/twig-theme-test-embed-tag-embedded.html.twig');
+  }
+
+}
-- 
GitLab