|
|
@ -405,7 +405,7 @@ class TwigExtension extends \Twig_Extension { |
|
|
|
// @code |
|
|
|
// @code |
|
|
|
// {{ 'now'|date('Y') }} |
|
|
|
// {{ 'now'|date('Y') }} |
|
|
|
// @endcode |
|
|
|
// @endcode |
|
|
|
$filters[] = new \Twig_SimpleFilter('php', [$this, 'phpFilter']); |
|
|
|
$filters[] = new \Twig_SimpleFilter('php', [$this, 'phpFilter'], ['needs_context' => TRUE]); |
|
|
|
} |
|
|
|
} |
|
|
|
return $filters; |
|
|
|
return $filters; |
|
|
|
} |
|
|
|
} |
|
|
@ -1286,17 +1286,20 @@ class TwigExtension extends \Twig_Extension { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Evaluates a string of PHP code. |
|
|
|
* Evaluates a string of PHP code. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @param array $context |
|
|
|
|
|
|
|
* Twig context. |
|
|
|
* @param string $code |
|
|
|
* @param string $code |
|
|
|
* Valid PHP code to be evaluated. |
|
|
|
* Valid PHP code to be evaluated. |
|
|
|
* |
|
|
|
* |
|
|
|
* @return mixed |
|
|
|
* @return mixed |
|
|
|
* The eval() result. |
|
|
|
* The eval() result. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function phpFilter($code) { |
|
|
|
public function phpFilter(array $context, $code) { |
|
|
|
|
|
|
|
// Make Twig variables available in PHP code. |
|
|
|
|
|
|
|
extract($context); |
|
|
|
ob_start(); |
|
|
|
ob_start(); |
|
|
|
// @codingStandardsIgnoreStart |
|
|
|
// phpcs:ignore Drupal.Functions.DiscouragedFunctions.Discouraged |
|
|
|
print eval($code); |
|
|
|
print eval($code); |
|
|
|
// @codingStandardsIgnoreEnd |
|
|
|
|
|
|
|
$output = ob_get_contents(); |
|
|
|
$output = ob_get_contents(); |
|
|
|
ob_end_clean(); |
|
|
|
ob_end_clean(); |
|
|
|
return $output; |
|
|
|
return $output; |
|
|
|