This repository was archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgraphql_twig.module
More file actions
51 lines (46 loc) · 1.37 KB
/
graphql_twig.module
File metadata and controls
51 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Implements hook_theme().
*
* Auto-generate theme hooks for graphql pages and blocks.
*/
function graphql_twig_theme($existing, $type, $theme, $path) {
/** @var \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler */
$themeHandler = \Drupal::service('theme_handler');
$theme = [];
foreach ($themeHandler->listInfo() as $themeName => $info) {
// Register twig routes as theme hooks.
if (isset($info->info['routes'])) {
foreach ($info->info['routes'] as $name => $route) {
$theme[$name] = [
'variables' => [
'graphql_arguments' => [],
'graphql_ext' => $name,
],
'function' => '_graphql_twig_missing_template',
];
}
}
// Register twig blocks as theme hooks.
if (isset($info->info['blocks'])) {
foreach ($info->info['blocks'] as $name => $block) {
$theme[$name] = [
'variables' => [
'graphql_arguments' => [],
'graphql_ext' => $name,
],
'function' => '_graphql_twig_missing_template',
];
}
}
}
return $theme;
}
/**
* Emits an error message if a dynamic route template is missing.
*/
function _graphql_twig_missing_template($variables) {
return '<div class="graphql-twig-errors">' . t('Missing template for %ext.', [
'%ext' => $variables['graphql_ext'],
]) . '</div>';
}