You are here

public function Debug::dump in Devel 8.3

Same name and namespace in other branches
  1. 8 src/Twig/Extension/Debug.php \Drupal\devel\Twig\Extension\Debug::dump()
  2. 8.2 src/Twig/Extension/Debug.php \Drupal\devel\Twig\Extension\Debug::dump()
  3. 4.x src/Twig/Extension/Debug.php \Drupal\devel\Twig\Extension\Debug::dump()

Provides debug function to Twig templates.

Handles 0, 1, or multiple arguments.

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.

Return value

string String representation of the input variables.

See also

\Drupal\devel\DevelDumperManager::dump()

File

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

Class

Debug
Provides the Devel debugging function within Twig templates.

Namespace

Drupal\devel\Twig\Extension

Code

public function dump(\Twig_Environment $env, array $context, array $args = []) {
  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');
  }
  else {
    $parameters = $this
      ->guessTwigFunctionParameters();
    foreach ($args as $index => $variable) {
      $name = !empty($parameters[$index]) ? $parameters[$index] : NULL;
      $this->dumper
        ->dump($variable, $name);
    }
  }
  return ob_get_clean();
}