|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_twig\Routing; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Extension\ThemeHandlerInterface; |
|
6
|
|
|
use Drupal\graphql_twig\Controller\RouteController; |
|
7
|
|
|
use Symfony\Component\Routing\Route; |
|
8
|
|
|
|
|
9
|
|
|
class GraphQLTwigRouter { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* The theme handler to collect routes from theme info files. |
|
13
|
|
|
* |
|
14
|
|
|
* @var \Drupal\Core\Extension\ThemeHandlerInterface |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $themeHandler; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* GraphQLTwigRouter constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler |
|
22
|
|
|
* The theme handler to collect routes from theme info files. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(ThemeHandlerInterface $themeHandler) { |
|
25
|
|
|
$this->themeHandler = $themeHandler; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Generate a list of routes based on theme info files. |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Symfony\Component\Routing\Route[] |
|
32
|
|
|
* A list of routes defined by themes. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function routes() { |
|
35
|
|
|
$routes = []; |
|
36
|
|
|
foreach ($this->themeHandler->listInfo() as $info) { |
|
37
|
|
|
if (isset($info->info['routes'])) { |
|
38
|
|
|
foreach ($info->info['routes'] as $name => $route) { |
|
39
|
|
|
$routes['graphql_twig.dynamic.' . $name] = new Route($route['path'], [ |
|
40
|
|
|
'_controller' => RouteController::class . ':page', |
|
41
|
|
|
'_title_callback' => RouteController::class . ':title', |
|
42
|
|
|
'_title' => isset($route['title']) ? $route['title'] : NULL, |
|
43
|
|
|
'_title_query' => isset($route['title_query']) ? $route['title_query'] : NULL, |
|
44
|
|
|
'_graphql_theme_hook' => $name, |
|
45
|
|
|
], isset($route['requirements']) ? $route['requirements'] : [ |
|
46
|
|
|
'_access' => 'TRUE', |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
return $routes; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|