diff --git a/src/Template/TwigExtension.php b/src/Template/TwigExtension.php index e43c178..0ba1c1e 100644 --- a/src/Template/TwigExtension.php +++ b/src/Template/TwigExtension.php @@ -1,6 +1,7 @@ $theme, 'variables' => $variables), - array('ignore_missing' => (bool) $ignore_missing), + ['theme' => $theme, 'variables' => $variables], + [], $lineno, $tag ); @@ -25,23 +25,9 @@ class TwigNodeTheme extends \Twig_Node implements \Twig_NodeOutputInterface { public function compile(\Twig_Compiler $compiler) { $compiler->addDebugInfo($this); - if ($this->getAttribute('ignore_missing')) { - $compiler->write("try {\n") - ->indent(); - } - $compiler->write('echo ') ->subcompile(new \Twig_Node_Expression_Function('theme', new \Twig_Node([$this->getNode('theme'), $this->getNode('variables')]), $this->getLine())) ->raw("; \n"); - - if ($this->getAttribute('ignore_missing')) { - $compiler->outdent() - ->write("} catch (Twig_Error_Loader \$e) {\n") - ->indent() - ->write("// ignore missing theme implementation\n") - ->outdent() - ->write("}\n\n"); - } } } diff --git a/src/Template/TwigThemeTokenParser.php b/src/Template/TwigThemeTokenParser.php index 1837463..e39d3b8 100644 --- a/src/Template/TwigThemeTokenParser.php +++ b/src/Template/TwigThemeTokenParser.php @@ -8,7 +8,7 @@ namespace Drupal\components\Template; * @code * {% * theme 'item_list' with { - * 'items: [], + * items: [], * } * %} * @endcode @@ -21,26 +21,18 @@ class TwigThemeTokenParser extends \Twig_TokenParser { public function parse(\Twig_Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); - list($variables, $ignore_missing) = $this->parseArguments(); - - return new TwigNodeTheme($expr, $variables, $ignore_missing, $token->getLine(), $this->getTag()); + return new TwigNodeTheme($expr, $this->parseArguments(), $token->getLine(), $this->getTag()); } /** * Parses the arguments. * - * @return array + * @return \Twig_Node_Expression + * A node expression containing the variables list. */ protected function parseArguments() { $stream = $this->parser->getStream(); - $ignore_missing = FALSE; - if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'ignore')) { - $stream->expect(\Twig_Token::NAME_TYPE, 'missing'); - - $ignore_missing = TRUE; - } - $variables = NULL; if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) { $variables = $this->parser->getExpressionParser()->parseExpression(); @@ -48,7 +40,7 @@ class TwigThemeTokenParser extends \Twig_TokenParser { $stream->expect(\Twig_Token::BLOCK_END_TYPE); - return [$variables, $ignore_missing]; + return $variables; } /**