public function TwigExtension::drupalDump in Twig VarDumper 8
Same name and namespace in other branches
- 8.2 src/TwigExtension.php \Drupal\twig_vardumper\TwigExtension::drupalDump()
- 3.0.x src/TwigExtension.php \Drupal\twig_vardumper\TwigExtension::drupalDump()
Dumps information about variables.
Parameters
\Twig_Environment $env: Enviroment values.
array $context: Context values.
File
- src/
TwigExtension.php, line 42
Class
- TwigExtension
- Twig extension with some useful functions and filters.
Namespace
Drupal\twig_vardumperCode
public function drupalDump(\Twig_Environment $env, array $context) {
if (!$env
->isDebug()) {
return;
}
$var_dumper = '\\Symfony\\Component\\VarDumper\\VarDumper';
if (class_exists($var_dumper)) {
$count = func_num_args();
if (2 === $count) {
$vars = [];
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$vars[$key] = $value;
}
}
call_user_func($var_dumper . '::dump', $vars);
}
else {
for ($i = 2; $i < $count; ++$i) {
call_user_func($var_dumper . '::dump', func_get_arg($i));
}
}
}
else {
trigger_error('Could not dump the variable because symfony/var-dumper component is not installed.', E_USER_WARNING);
}
}