Skip to content
Snippets Groups Projects

Argument declaration and print output

1 unresolved thread
2 files
+ 14
10
Compare changes
  • Side-by-side
  • Inline
Files
2
<?php
declare(strict_types = 1);
namespace Drupal\devel_debug_log\Twig;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Template\TwigEnvironment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@@ -24,33 +27,33 @@ class DevelDebugLogExtension extends AbstractExtension {
* {@inheritdoc}
*/
public function getFunctions() {
return array(
new TwigFunction('ddl', array($this, 'ddl'), array(
return [
new TwigFunction('ddl', [$this, 'ddl'], [
'needs_environment' => TRUE,
'needs_context' => TRUE,
)),
);
]),
];
}
/**
* Provides ddl function to Twig templates.
*
* @param Twig_Environment $env
* @param \Drupal\Core\Template\TwigEnvironment $env
* The twig environment instance.
* @param array $context
* An array of parameters passed to the template.
*/
public function ddl(\Twig_Environment $env, array $context) {
// Don't do anything unless twig_debug is enabled. This reads from the Twig
public function ddl(TwigEnvironment $env, array $context) {
// Don't do anything unless twig_debug is enabled. This reads from the Twig.
if (!$env->isDebug()) {
return;
}
if (func_num_args() === 2) {
// No arguments passed, display full Twig context.
$ddl_variables = array();
$ddl_variables = [];
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
if (!$value instanceof TwigEnvironment) {
$ddl_variables[$key] = $value;
}
}
Loading