EntityToJsonDeriver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 5 1
A __construct() 0 3 1
A getDerivativeDefinitions() 0 7 2
1
<?php
2
3
namespace Drupal\graphql_json\Plugin\Deriver;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
6
use Drupal\Core\Extension\ModuleHandlerInterface;
7
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
/**
11
 * Only add the field if the serializer module is enabled.
12
 */
13
class EntityToJsonDeriver extends DeriverBase implements ContainerDeriverInterface {
14
15
  /**
16
   *  The module handler service.
17
   *
18
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
19
   */
20
  protected $moduleHandler;
21
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public static function create(ContainerInterface $container, $basePluginId) {
26
    return new static(
27
      $container->get('module_handler')
28
    );
29
  }
30
31
  /**
32
   * Creates a EntityToJsonDeriver object.
33
   *
34
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
35
   *   The module handler service.
36
   */
37
  public function __construct(ModuleHandlerInterface $moduleHandler) {
38
    $this->moduleHandler = $moduleHandler;
39
  }
40
41
  /**
42
   * {@inheritdoc}
43
   */
44
  public function getDerivativeDefinitions($basePluginDefinition) {
45
    if ($this->moduleHandler->moduleExists('serialization')) {
46
      $this->derivatives['entity_to_json'] = $basePluginDefinition;
47
    }
48
49
    return parent::getDerivativeDefinitions($basePluginDefinition);
50
  }
51
52
}
53