You are here

class DevelDebugLogExtension in Devel Debug Log 8

Provides the Debug log debugging function within Twig templates.

Hierarchy

Expanded class hierarchy of DevelDebugLogExtension

1 string reference to 'DevelDebugLogExtension'
devel_debug_log.services.yml in ./devel_debug_log.services.yml
devel_debug_log.services.yml
1 service uses DevelDebugLogExtension
devel_debug_log.twig.devel_debug_log_extension in ./devel_debug_log.services.yml
Drupal\devel_debug_log\Twig\DevelDebugLogExtension

File

src/Twig/DevelDebugLogExtension.php, line 10

Namespace

Drupal\devel_debug_log\Twig
View 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

Namesort descending Modifiers Type Description Overrides
DevelDebugLogExtension::ddl public function Provides ddl function to Twig templates.
DevelDebugLogExtension::getFunctions public function
DevelDebugLogExtension::getName public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.