function Debug::doDump

Same name in other branches
  1. 5.x src/Twig/Extension/Debug.php \Drupal\devel\Twig\Extension\Debug::doDump()

Parameters

\Twig_Environment $env: The twig environment instance.

array $context: An array of parameters passed to the template.

array $args: An array of parameters passed the function.

string $plugin_id: The plugin id. Defaults to null.

Return value

string|null String representation of the input variables, or null if twig_debug mode is tunred off.

2 calls to Debug::doDump()
Debug::dump in src/Twig/Extension/Debug.php
Provides debug function to Twig templates.
Debug::kint in src/Twig/Extension/Debug.php
Similar to dump() but always uses the kint dumper if available.

File

src/Twig/Extension/Debug.php, line 103

Class

Debug
Provides the Devel debugging function within Twig templates.

Namespace

Drupal\devel\Twig\Extension

Code

private function doDump(\Twig_Environment $env, array $context, array $args = [], $plugin_id = NULL) {
    if (!$env->isDebug()) {
        return NULL;
    }
    ob_start();
    // No arguments passed, display full Twig context.
    if (empty($args)) {
        $context_variables = $this->getContextVariables($context);
        $this->dumper
            ->dump($context_variables, 'Twig context', $plugin_id);
    }
    else {
        $parameters = $this->guessTwigFunctionParameters();
        foreach ($args as $index => $variable) {
            $name = !empty($parameters[$index]) ? $parameters[$index] : NULL;
            $this->dumper
                ->dump($variable, $name, $plugin_id);
        }
    }
    return ob_get_clean();
}