diff --git a/src/Twig/Notifications.php b/src/Twig/Notifications.php new file mode 100644 index 00000000..d03f1c57 --- /dev/null +++ b/src/Twig/Notifications.php @@ -0,0 +1,67 @@ +environment = $environment; + $this->config = $config; + } + + public function success(string $subject, string $body) + { + $this->render('Success: ' . $subject, $body, 'success'); + + return null; + } + + public function danger(string $subject, string $body) + { + $this->render('Danger: ' . $subject, $body, 'danger'); + + return null; + } + + public function info(string $subject, string $body) + { + $this->render('Info: ' . $subject, $body, 'info'); + + return null; + } + + public function warning(string $subject, string $body) + { + $this->render('Warning: ' . $subject, $body, 'warning'); + + return null; + } + + private function render(string $subject, string $body, string $type): void + { + $twigVars = [ + 'subject' => $subject, + 'body' => $body, + 'type' => $type, + 'basePath' => $this->config->getPath('site'), + 'backtrace' => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7), + ]; + + $output = $this->environment->render('@bolt/_partials/notification.html.twig', $twigVars); + + echo new Markup($output, 'utf-8'); + } +} diff --git a/templates/_partials/notification.html.twig b/templates/_partials/notification.html.twig new file mode 100644 index 00000000..0a072e03 --- /dev/null +++ b/templates/_partials/notification.html.twig @@ -0,0 +1,107 @@ + +
')|raw }}{%- if frame.type is not empty -%}
+
+ {{- frame.class|split('\\')|last()|excerpt(24) -}}{{- frame.type -}}
+ {%- endif -%}
+ {{- frame.function -}}() - line {{ frame.line }}
+