Problem/Motivation

Twig has a wonderful AST debug printer which is broken with Drupal.

Steps to reproduce

$twig = \Drupal::service('twig');
$string = '{{ foo }}';
$stream = $twig->tokenize(new \Twig\Source($string, '{# inline_template_start #}'));
$nodes = $twig->parse($stream);
$twig->compile($nodes);
print $nodes;

errors out with var_export does not handle circular references Node.php:56

I believe I have hunted the problem to the class resolver https://gist.github.com/chx/df272b847b2770be00f6b7b8bf1b5ff8 but it's not yet clear what are the next steps. To be continued tomorrow.

Proposed resolution

Note adding DependencySerializationTrait to TwigExtension does not help -- especially because ClassResolver already has it. Yet, the problem lies somewhere there. Hiding the container from the eyes of var_export does help, ContainerAwareTrait could store https://gist.github.com/chx/6a0388e79b527b6bbcea6956f5225821 instead of the raw container. This is, of course, extremely ugly. To be continued tomorrow.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Charlie ChX Negyesi created an issue. See original summary.

ghost of drupal past’s picture

Title: The renderer service breaks the twig debug node printer » Drupal Twig extension breaks the twig debug node printer
ghost of drupal past’s picture

Status: Active » Closed (won't fix)