5 use Drupal\Core\Entity\Query\QueryFactory;
6 use Symfony\Component\Routing\Route;
7 use Symfony\Component\Routing\RouteCollection;
20 public function __construct(
string $appRoot, QueryFactory $entityQuery) {
21 $this->appRoot = $appRoot;
22 $this->entityQuery = $entityQuery;
29 $routes =
new RouteCollection();
31 $this->addStaticPages($routes);
33 $routes->addRequirements([
'_access' =>
'TRUE']);
42 $base = $this->appRoot .
"/data-catalog-frontend/public/";
43 $sub = str_replace($base,
"", $path);
44 return str_replace(
"/",
"__", $sub);
50 private function expandDirectories($base_dir) {
53 if (!file_exists($base_dir)) {
57 foreach (scandir($base_dir) as $file) {
58 if ($file ==
'.' || $file ==
'..') {
61 $dir = $base_dir . DIRECTORY_SEPARATOR . $file;
63 $directories[] = $dir;
64 $directories = array_merge($directories, $this->expandDirectories($dir));
81 private function routeHelper(
string $path,
string $name) : Route {
85 '_controller' =>
'\Drupal\dkan_frontend\Controller\Page::page',
89 $route->setMethods([
'GET']);
96 private function addStaticPages(RouteCollection $routes) {
97 $base = $this->appRoot .
"/data-catalog-frontend/public";
98 $possible_pages = $this->expandDirectories($base);
100 foreach ($possible_pages as $possible_page) {
101 if (file_exists($possible_page .
"/index.html")) {
103 $path = str_replace($base,
"", $possible_page);
104 $routes->add($name, $this->routeHelper($path, $name));
111 '_controller' =>
'\Drupal\dkan_frontend\Controller\Page::page',
115 $route->setMethods([
'GET']);
116 $routes->add(
'home', $route);