Completed
Push — 8.x-1.x ( 2f413c...494d52 )
by Philipp
01:14
created

graphql_twig.module::_graphql_twig_missing_template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Implements hook_theme().
5
 *
6
 * Auto-generate theme hooks for graphql pages and blocks.
7
 */
8
function graphql_twig_theme($existing, $type, $theme, $path) {
0 ignored issues
show
Unused Code introduced by
The parameter $existing is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $theme is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
9
  /** @var \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler */
10
  $themeHandler = \Drupal::service('theme_handler');
11
  $theme = [];
12
  foreach ($themeHandler->listInfo() as $themeName => $info) {
13
14
    // Register twig routes as theme hooks.
15 View Code Duplication
    if (isset($info->info['routes'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
      foreach ($info->info['routes'] as $name => $route) {
17
        $theme[$name] = [
18
          'variables' =>  [
19
            'graphql_arguments' => [],
20
            'graphql_route' => $name,
21
          ],
22
          'function' => '_graphql_twig_missing_template',
23
        ];
24
      }
25
    }
26
27
    // Register twig blocks as theme hooks.
28 View Code Duplication
    if (isset($info->info['blocks'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
      foreach ($info->info['blocks'] as $name => $block) {
30
        $theme[$name] = [
31
          'variables' =>  [
32
            'graphql_arguments' => [],
33
            'graphql_route' => $name,
34
          ],
35
          'function' => '_graphql_twig_missing_template',
36
        ];
37
      }
38
    }
39
40
  }
41
  return $theme;
42
}
43
44
/**
45
 * Emits an error message if a dynamic route template is missing.
46
 */
47
function _graphql_twig_missing_template($variables) {
48
  return '<div class="error">' . t('Missing template for route %route.', [
49
    '%route' => $variables['graphql_route'],
50
  ]) . '</div>';
51
}
52