getDerivativeDefinitions()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 1
dl 0
loc 14
rs 9.4888
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\graphql_twig\Plugin\Deriver;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
6
use Drupal\Core\Extension\ThemeHandlerInterface;
7
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8
use Drupal\Core\StringTranslation\StringTranslationTrait;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
11
class GraphQLTwigBlockDeriver extends DeriverBase implements ContainerDeriverInterface {
12
  use StringTranslationTrait;
13
14
  /**
15
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
16
   */
17
  protected $themeHandler;
18
19
  public static function create(ContainerInterface $container, $base_plugin_id) {
20
    return new static($container->get('theme_handler'));
21
  }
22
23
  public function __construct(ThemeHandlerInterface $themeHandler) {
24
    $this->themeHandler = $themeHandler;
25
  }
26
27
  public function getDerivativeDefinitions($base_plugin_definition) {
28
    foreach ($this->themeHandler->listInfo() as $themeName => $info) {
29
      if (isset($info->info['blocks'])) {
30
        foreach ($info->info['blocks'] as $name => $block) {
31
          $this->derivatives[$name] = [
32
              'admin_label' => $this->t($block['label']),
33
              'graphql_theme_hook' => $name,
34
              'graphql_parameters' => isset($block['parameters']) ? $block['parameters'] : [],
35
          ] + $base_plugin_definition;
36
        }
37
      }
38
    }
39
    return $this->derivatives;
40
  }
41
42
43
}
44