It would be very useful extend the devel functionalities and provide Twig debug functions that use the pluggable dumper system even for debug twig. In this way every external libraries for which exist a dumper plugin (adapter) can be used for debug twig with no development/impact.

The idea is:

Create functions for dump twig variables (like currently kint() does)

{{ devel_dump() }}
{{ kpr() }}

Create functions for set message with the dumped variables (ala dpm())

{{ devel_message() }}
{{ dpm() }}
{{ dsm() }}

Some other modules may benefit from this initiative and colud provide valid alternatives to debug twig with kint :)
- Vardumper - see https://www.drupal.org/project/vardumper
- Ladybug - WIP see #2707967: Add support for Devel dumper system

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

willzyx created an issue. See original summary.

willzyx’s picture

Status: Active » Needs review
FileSize
4.53 KB
willzyx’s picture

Status: Needs review » Needs work

The last submitted patch, 3: dumper_system_part_ii-2725395-3.patch, failed testing.

willzyx’s picture

Status: Needs work » Needs review
FileSize
14.66 KB
900 bytes

seems that DoctrineDebug::export() and DoctrineDebug::dump() produce a very different output

willzyx’s picture

  1. +++ b/src/Plugin/Devel/Dumper/DoctrineDebug.php
    @@ -25,10 +25,15 @@ class DoctrineDebug extends DevelDumperBase {
       public function dump($input, $name = NULL) {
    -    if ($name) {
    -      echo $name . ' => ';
    -    }
    -    Debug::dump($input);
    +    $name = $name ? $name . ' => ' : '';
    +    $variable = Debug::export($input, 6);
    +
    +    ob_start();
    +    print_r($variable);
    +    $dump = ob_get_contents();
    +    ob_end_clean();
    +
    +    echo '<pre>' . $name . $dump . '</pre>';
       }
    

    IMHO we should make DoctrineDebug::dump() output (use var_dump()) more similar to the DoctrineDebug::export() output (use print_r()) or at least allow HTML tags in dump for take advantage of Xdebug (if enabled) var_dump() implementation. Change DoctrineDebug::dump() in this issue seems to be out of scope so reverted

  2. +++ b/tests/src/Kernel/DevelDumperTestTrait.php
    @@ -0,0 +1,62 @@
    +  private function getDumperDump($input, $name = NULL) {
    +    $output = \Drupal::service('devel.dumper')->export($input, $name);
    +    return rtrim($output);
    

    We need different functions for test {{ devel_dump() }} and {{ devel_message() }} since the first internally use DevelDumperManager::dump() while the second DevelDumperManager::export()

willzyx’s picture

If no one have objections/suggestions I'm going to commit this in the next few days

dawehner’s picture

Just stumbled upon this issue. Really great work! No objections, this is for sure.

+++ b/src/Twig/Extension/Debug.php
@@ -0,0 +1,159 @@
+    if (!$env->isDebug()) {
+      return;
+    }

this is a super nice idea, as it leads to less broken deployments

lussoluca’s picture

Status: Needs review » Reviewed & tested by the community

Great work! RTBC for me

https://www.drupal.org/project/vardumper already works with the new plugin infrastructure

  • willzyx committed 8dc277d on 8.x-1.x
    Issue #2725395 by willzyx: Dumper system Part II:  Add basic Twig debug...
willzyx’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.