DevelDebugLogExtension.php in Devel Debug Log 8
File
src/Twig/DevelDebugLogExtension.php
View source
<?php
namespace Drupal\devel_debug_log\Twig;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class DevelDebugLogExtension extends \Twig_Extension {
use StringTranslationTrait;
public function getName() {
return 'ddl';
}
public function getFunctions() {
return array(
new \Twig_SimpleFunction('ddl', array(
$this,
'ddl',
), array(
'needs_environment' => TRUE,
'needs_context' => TRUE,
)),
);
}
public function ddl(\Twig_Environment $env, array $context) {
if (!$env
->isDebug()) {
return;
}
if (func_num_args() === 2) {
$ddl_variables = array();
foreach ($context as $key => $value) {
if (!$value instanceof \Twig_Template) {
$ddl_variables[$key] = $value;
}
}
ddl($ddl_variables, $this
->t('Context as array'));
}
else {
$args = array_slice(func_get_args(), 2);
if (isset($args[1])) {
ddl($args[0], (string) $args[1]);
}
else {
ddl($args[0]);
}
}
}
}