function Debug::doDump

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

Writes the debug information for Twig templates.

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|null $plugin_id: The plugin id. Defaults to null.

Return value

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

1 call to Debug::doDump()
Debug::dump in src/Twig/Extension/Debug.php
Provides debug function to Twig templates.

File

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

Class

Debug
Provides the Devel debugging function within Twig templates.

Namespace

Drupal\devel\Twig\Extension

Code

private function doDump(Environment $env, array $context, array $args = [], ?string $plugin_id = NULL) : false|string|null {
  if (!$env->isDebug()) {
    return NULL;
  }
  ob_start();
  // No arguments passed, display full Twig context.
  if ($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]) ? NULL : $parameters[$index];
      $this->dumper
        ->dump($variable, $name, $plugin_id);
    }
  }
  return ob_get_clean();
}