From a96c19d06f5980ee8e85dc997cff43baf6b24af3 Mon Sep 17 00:00:00 2001 From: "Derek \"tachyon\" Reese" Date: Mon, 24 Feb 2020 15:11:40 -0500 Subject: [PATCH] Adds a try catch to twig pattern renders feat(PatternLibrary*) --- src/Plugin/PatternLibrary/PatternLibraryJSON.php | 8 +------- src/Plugin/PatternLibrary/PatternLibraryTwig.php | 9 +++++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Plugin/PatternLibrary/PatternLibraryJSON.php b/src/Plugin/PatternLibrary/PatternLibraryJSON.php index 33a17a5..c287fdd 100644 --- a/src/Plugin/PatternLibrary/PatternLibraryJSON.php +++ b/src/Plugin/PatternLibrary/PatternLibraryJSON.php @@ -6,6 +6,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\State\StateInterface; +use Drupal\patternkit\Annotation\PatternLibrary; use Drupal\patternkit\JSONSchemaEditorTrait; use Drupal\patternkit\Pattern; use Drupal\patternkit\PatternEditorConfig; @@ -24,13 +25,6 @@ class PatternLibraryJSON extends PatternLibraryPluginDefault implements ContainerFactoryPluginInterface { use JSONSchemaEditorTrait; - /** - * State machine service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - /** * Attaches services. * diff --git a/src/Plugin/PatternLibrary/PatternLibraryTwig.php b/src/Plugin/PatternLibrary/PatternLibraryTwig.php index bbf212d..9a32072 100644 --- a/src/Plugin/PatternLibrary/PatternLibraryTwig.php +++ b/src/Plugin/PatternLibrary/PatternLibraryTwig.php @@ -83,8 +83,13 @@ public function render(array $assets): array { $bare = basename($file); /** @var \Drupal\Core\Template\TwigEnvironment $twig */ $twig = \Drupal::service('twig'); - $template = $twig->load("$namespace/$pattern->filename"); - $elements[] = $template->render($pattern->config ?? []); + try { + $template = $twig->load("$namespace/$pattern->filename"); + $elements[] = $template->render($pattern->config ?? []); + } + catch (\Exception $exception) { + // @todo Use twig logger and log this exception. + } } return $elements; }