From 2fb914707c159c895886570f74c3ff2aaf1c13a2 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Tue, 17 Jul 2018 10:00:43 -0100 Subject: [PATCH] add array of css/js Signed-off-by: Maxence Lange --- lib/Controller/NavigationController.php | 51 +++++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index e1af5a6..386e9a0 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -88,23 +88,58 @@ public function navigate(): TemplateResponse { foreach ($widgetFrames as $frame) { $tmpl = $frame->getWidget() ->getTemplate(); - if (!array_key_exists('app', $tmpl)) { + if (!is_array($tmpl) || !array_key_exists('app', $tmpl)) { continue; } - if (array_key_exists('css', $tmpl)) { - Util::addStyle($tmpl['app'], $tmpl['css']); - } - - if (array_key_exists('js', $tmpl)) { - Util::addScript($tmpl['app'], $tmpl['js']); - } + $this->includeWidgetCss($tmpl); + $this->includeWidgetJs($tmpl); } return new TemplateResponse(Application::APP_NAME, 'navigate', []); } + /** + * @param array $tmpl + */ + private function includeWidgetCss(array $tmpl) { + if (!array_key_exists('css', $tmpl)) { + return; + } + + $css = $tmpl['css']; + if (!is_array($css)) { + $css = [$css]; + } + + foreach ($css as $file) { + Util::addStyle($tmpl['app'], $file); + } + + } + + + /** + * @param array $tmpl + */ + private function includeWidgetJs(array $tmpl) { + if (!array_key_exists('js', $tmpl)) { + return; + } + + $js = $tmpl['js']; + if (!is_array($js)) { + $js = [$js]; + } + + foreach ($js as $file) { + Util::addScript($tmpl['app'], $file); + } + + } + + /** * @NoAdminRequired * @NoSubAdminRequired