class DevelDebugLogExtension in Devel Debug Log 8
Provides the Debug log debugging function within Twig templates.
Hierarchy
- class \Drupal\devel_debug_log\Twig\DevelDebugLogExtension extends \Drupal\devel_debug_log\Twig\Twig_Extension uses StringTranslationTrait
Expanded class hierarchy of DevelDebugLogExtension
1 string reference to 'DevelDebugLogExtension'
1 service uses DevelDebugLogExtension
File
- src/
Twig/ DevelDebugLogExtension.php, line 10
Namespace
Drupal\devel_debug_log\TwigView source
class DevelDebugLogExtension extends \Twig_Extension {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getName() {
return 'ddl';
}
/**
* {@inheritdoc}
*/
public function getFunctions() {
return array(
new \Twig_SimpleFunction('ddl', array(
$this,
'ddl',
), array(
'needs_environment' => TRUE,
'needs_context' => TRUE,
)),
);
}
/**
* Provides ddl function to Twig templates.
*
* @param Twig_Environment $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
if (!$env
->isDebug()) {
return;
}
if (func_num_args() === 2) {
// No arguments passed, display full Twig context.
$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]);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DevelDebugLogExtension:: |
public | function | Provides ddl function to Twig templates. | |
DevelDebugLogExtension:: |
public | function | ||
DevelDebugLogExtension:: |
public | function | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |