Skip to content

Commit f4eeed8

Browse files
authored
Merge pull request #15 from cybtachyon/twig-render-catch
Adds a try catch to twig pattern renders
2 parents b2c1ea0 + a96c19d commit f4eeed8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Plugin/PatternLibrary/PatternLibraryJSON.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\Core\Config\ConfigFactoryInterface;
77
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
88
use Drupal\Core\State\StateInterface;
9+
use Drupal\patternkit\Annotation\PatternLibrary;
910
use Drupal\patternkit\JSONSchemaEditorTrait;
1011
use Drupal\patternkit\Pattern;
1112
use Drupal\patternkit\PatternEditorConfig;
@@ -24,13 +25,6 @@
2425
class PatternLibraryJSON extends PatternLibraryPluginDefault implements ContainerFactoryPluginInterface {
2526
use JSONSchemaEditorTrait;
2627

27-
/**
28-
* State machine service.
29-
*
30-
* @var \Drupal\Core\State\StateInterface
31-
*/
32-
protected $state;
33-
3428
/**
3529
* Attaches services.
3630
*

src/Plugin/PatternLibrary/PatternLibraryTwig.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ public function render(array $assets): array {
8383
$bare = basename($file);
8484
/** @var \Drupal\Core\Template\TwigEnvironment $twig */
8585
$twig = \Drupal::service('twig');
86-
$template = $twig->load("$namespace/$pattern->filename");
87-
$elements[] = $template->render($pattern->config ?? []);
86+
try {
87+
$template = $twig->load("$namespace/$pattern->filename");
88+
$elements[] = $template->render($pattern->config ?? []);
89+
}
90+
catch (\Exception $exception) {
91+
// @todo Use twig logger and log this exception.
92+
}
8893
}
8994
return $elements;
9095
}

0 commit comments

Comments
 (0)