From 3cb6563c407c1b1903e4103c86498bf72be9fd74 Mon Sep 17 00:00:00 2001 From: eli Date: Wed, 6 Oct 2021 00:34:27 +0100 Subject: [PATCH] [TWIG][EndShowStyles] Route as an event argument --- components/Left/Left.php | 2 +- components/Right/Right.php | 2 +- components/Search/Search.php | 2 +- .../AttachmentShowRelated.php | 17 ++++++++++++++++- src/Twig/Runtime.php | 4 ++-- templates/base.html.twig | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/components/Left/Left.php b/components/Left/Left.php index 67816aeebe..96ff430fc3 100644 --- a/components/Left/Left.php +++ b/components/Left/Left.php @@ -31,7 +31,7 @@ class Left extends Component * * @return bool hook value; true means continue processing, false means stop. */ - public function onEndShowStyles(array &$styles): bool + public function onEndShowStyles(array &$styles, string $route): bool { $styles[] = 'components/Left/assets/css/view.css'; return Event::next; diff --git a/components/Right/Right.php b/components/Right/Right.php index 063aedf5a5..fbc505fceb 100644 --- a/components/Right/Right.php +++ b/components/Right/Right.php @@ -31,7 +31,7 @@ class Right extends Component * * @return bool hook value; true means continue processing, false means stop. */ - public function onEndShowStyles(array &$styles): bool + public function onEndShowStyles(array &$styles, string $route): bool { $styles[] = 'components/Right/assets/css/view.css'; return Event::next; diff --git a/components/Search/Search.php b/components/Search/Search.php index f0020b49f6..dec35b3ae0 100644 --- a/components/Search/Search.php +++ b/components/Search/Search.php @@ -76,7 +76,7 @@ class Search extends Component * * @return bool hook value; true means continue processing, false means stop. */ - public function onEndShowStyles(array &$styles): bool + public function onEndShowStyles(array &$styles, string $route): bool { $styles[] = 'components/Search/assets/css/view.css'; return Event::next; diff --git a/plugins/AttachmentShowRelated/AttachmentShowRelated.php b/plugins/AttachmentShowRelated/AttachmentShowRelated.php index 70004320bf..b655032272 100644 --- a/plugins/AttachmentShowRelated/AttachmentShowRelated.php +++ b/plugins/AttachmentShowRelated/AttachmentShowRelated.php @@ -31,7 +31,7 @@ class AttachmentShowRelated extends Plugin { public function onAppendRightPanelBlock($vars, &$res): bool { - if ($vars['path'] == 'attachment_show') { + if ($vars['path'] === 'attachment_show') { $related_notes = DB::dql('select n from attachment_to_note an ' . 'join note n with n.id = an.note_id ' . 'where an.attachment_id = :attachment_id', ['attachment_id' => $vars['vars']['attachment_id']]); @@ -43,4 +43,19 @@ class AttachmentShowRelated extends Plugin } return Event::next; } + + /** + * Output our dedicated stylesheet + * + * @param array $styles stylesheets path + * + * @return bool hook value; true means continue processing, false means stop. + */ + public function onEndShowStyles(array &$styles, string $path): bool + { + if ($path === 'attachment_show') { + $styles[] = '/assets/default_theme/css/pages/feeds.css'; + } + return Event::next; + } } \ No newline at end of file diff --git a/src/Twig/Runtime.php b/src/Twig/Runtime.php index e1f20390d0..695ba51555 100644 --- a/src/Twig/Runtime.php +++ b/src/Twig/Runtime.php @@ -82,10 +82,10 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface * @return array|mixed * @codeCoverageIgnore */ - public function getShowStylesheets() + public function getShowStylesheets($route) { $styles = []; - Event::handle('EndShowStyles', [&$styles]); + Event::handle('EndShowStyles', [&$styles, $route]); return $styles; } diff --git a/templates/base.html.twig b/templates/base.html.twig index b22bba6bbf..8a84b91fc7 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -15,7 +15,7 @@ - {% for stylesheet in show_stylesheets() %} + {% for stylesheet in show_stylesheets(app.request.get('_route')) %} {% endfor %} {% endblock %}