mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 04:27:00 +00:00
fix: #4033 add missing unwrap call when a TemplateWrapper instance can be present
This commit is contained in:
@@ -198,7 +198,7 @@ final class ModuleNode extends Node
|
||||
->raw(', ')
|
||||
->repr($node->getTemplateLine())
|
||||
->raw(");\n")
|
||||
->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i))
|
||||
->write(sprintf("if (!\$_trait_%s->unwrap()->isTraitable()) {\n", $i))
|
||||
->indent()
|
||||
->write("throw new RuntimeError('Template \"'.")
|
||||
->subcompile($trait->getNode('template'))
|
||||
@@ -207,7 +207,7 @@ final class ModuleNode extends Node
|
||||
->raw(", \$this->source);\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->getBlocks();\n\n", $i, $i))
|
||||
->write(sprintf("\$_trait_%s_blocks = \$_trait_%s->unwrap()->getBlocks();\n\n", $i, $i))
|
||||
;
|
||||
|
||||
foreach ($trait->getNode('targets') as $key => $value) {
|
||||
|
||||
+1
-1
@@ -464,7 +464,7 @@ abstract class Template
|
||||
}
|
||||
}
|
||||
} elseif ($parent = $this->getParent($context)) {
|
||||
yield from $parent->yieldBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this);
|
||||
yield from $parent->unwrap()->yieldBlock($name, $context, array_merge($this->blocks, $blocks), false, $templateContext ?? $this);
|
||||
} elseif (isset($blocks[$name])) {
|
||||
throw new RuntimeError(sprintf('Block "%s" should not call parent() in "%s" as the block does not exist in the parent template "%s".', $name, $blocks[$name][0]->getTemplateName(), $this->getTemplateName()), -1, $blocks[$name][0]->getSourceContext());
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
--TEST--
|
||||
Call to undefined method Twig\\TemplateWrapper::yieldBlock()
|
||||
--TEMPLATE--
|
||||
{% extends 'parent' %}
|
||||
{%- block content -%}
|
||||
{{ parent() }}
|
||||
child
|
||||
{%- endblock -%}
|
||||
--TEMPLATE(parent)--
|
||||
{% extends ['unknowngrandparent', 'grandparent'] %}
|
||||
--TEMPLATE(grandparent)--
|
||||
{%- block content -%}
|
||||
grandparent
|
||||
{%- endblock -%}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
grandparent
|
||||
child
|
||||
Reference in New Issue
Block a user