Skip to content

Commit

Permalink
feat(twig): support storybook twig extension in linting (#613)
Browse files Browse the repository at this point in the history
The automatic twig linting throws a fatal error when the Storybook module is
present, as the static tests don't bootstrap Drupal to discover twig
extensions. Since bootstrapping Drupal is expensive, instead check and load the
twig extension manually.

Re https://github.com/Lullabot/appstate-drupal/pull/33#issuecomment-2231807673

Co-authored-by: Sally Young <[email protected]>
Co-authored-by: Andrew Berry <[email protected]>
  • Loading branch information
3 people committed Jul 26, 2024
1 parent c528a06 commit cea2266
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bin/drainpipe-twig-linter
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ $themeManager = Mockery::mock(ThemeManagerInterface::class);
$dateFormatter = Mockery::mock(DateFormatterInterface::class);
$fileUrlGenerator = Mockery::mock(FileUrlGenerator::class);

if (class_exists('\TwigStorybook\Twig\TwigExtension')) {
$composer_json = json_decode(file_get_contents(__DIR__ . '/../../../../composer.json'), true);
if (json_last_error()) {
throw new \RuntimeException('Could not parse composer.json');
}

$web_root = $composer_json['extra']['drupal-scaffold']['locations']['web-root'];
$twig->addExtension(new \TwigStorybook\Twig\TwigExtension(new \TwigStorybook\Service\StoryCollector(), '/../../../../' . $web_root));
}

$twig->addExtension(new TwigExtension($renderer, $urlGenerator, $themeManager, $dateFormatter, $fileUrlGenerator));

$lintCommand = new LintCommand($twig);
Expand Down

0 comments on commit cea2266

Please sign in to comment.