diff --git a/Admin/Install/Search.php b/Admin/Install/Search.php new file mode 100644 index 0000000..6122bdd --- /dev/null +++ b/Admin/Install/Search.php @@ -0,0 +1,43 @@ + __DIR__ . '/SearchCommands.php']); + } +} diff --git a/Admin/Install/SearchCommands.php b/Admin/Install/SearchCommands.php new file mode 100644 index 0000000..01482ed --- /dev/null +++ b/Admin/Install/SearchCommands.php @@ -0,0 +1,30 @@ + [ + [ + 'dest' => '\Modules\Navigation\Controller\SearchController:searchGoto', + 'verb' => RouteVerb::ANY, + 'permission' => [ + 'module' => SearchController::MODULE_NAME, + 'type' => PermissionType::READ, + ], + ], + ], +]; diff --git a/Controller/SearchController.php b/Controller/SearchController.php new file mode 100644 index 0000000..03a1846 --- /dev/null +++ b/Controller/SearchController.php @@ -0,0 +1,111 @@ +loadLanguage($request, $response, $request->getData('app')); + + $elements = NavElementMapper::getAll(); + $search = \explode(' ', $request->getData('search'))[1]; + + $found = null; + foreach ($elements as $element) { + if (empty($element->uri)) { + continue; + } + + $name = $this->app->l11nManager->getText( + $response->getHeader()->getL11n()->getLanguage() ?? 'en', + 'Navigation', '0', + $element->name, + ); + + if ($name === $search) { + $found = $element; + break; + } + } + + $response->getHeader()->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true); + $response->set($request->getUri()->__toString(), new Redirect(UriFactory::build($found->uri))); + } + + /** + * Load navigation language + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param string $app App name + * + * @return void + * + * @todo Orange-Management/Modules#190 & Orange-Management/Modules#181 + * The loading of the language file is slow since every module is loaded separately. + * This should either get cached per user or maybe put into one large language file per language (like the routes). + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + private function loadLanguage(RequestAbstract $request, ResponseAbstract $response, string $app) : void + { + $languages = $this->app->moduleManager->getLanguageFiles($request, $app); + $langCode = $response->getHeader()->getL11n()->getLanguage(); + + foreach ($languages as $path) { + $path = __DIR__ . '/../../..' . $path . '.' . $langCode . '.lang.php'; + + if (!\file_exists($path)) { + continue; + } + + /** @noinspection PhpIncludeInspection */ + $lang = include $path; + + $this->app->l11nManager->loadLanguage($langCode, 'Navigation', $lang); + } + } +} diff --git a/Theme/Backend/mid.tpl.php b/Theme/Backend/mid.tpl.php index 1815ca4..b2502fa 100644 --- a/Theme/Backend/mid.tpl.php +++ b/Theme/Backend/mid.tpl.php @@ -29,7 +29,7 @@ if (isset($this->nav[\Modules\Navigation\Models\NavigationType::CONTENT]) $uri = \phpOMS\Uri\UriFactory::build($link['nav_uri']); echo '