EntityRenderedDeriver::getDerivativeDefinitions()   A
last analyzed

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 22
rs 9.2222
cc 6
nc 5
nop 1
1
<?php
2
3
namespace Drupal\graphql_core\Plugin\Deriver\Fields;
4
5
use Drupal\Component\Plugin\Derivative\DeriverBase;
0 ignored issues
show
Bug introduced by
The type Drupal\Component\Plugin\Derivative\DeriverBase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Drupal\Core\Entity\ContentEntityTypeInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\ContentEntityTypeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\Entit...playRepositoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Drupal\Core\Entity\EntityTypeManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Entity\EntityTypeManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Plugin\Disco...ntainerDeriverInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Drupal\Core\StringTranslation\StringTranslationTrait;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\StringTransl...\StringTranslationTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Drupal\graphql\Utility\StringHelper;
12
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
class EntityRenderedDeriver extends DeriverBase implements ContainerDeriverInterface {
15
  use StringTranslationTrait;
16
17
  /**
18
   * The entity type manager service.
19
   *
20
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21
   */
22
  protected $entityTypeManager;
23
24
  /**
25
   * The entity display repository service.
26
   *
27
   * @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
28
   */
29
  protected $entityDisplayRepository;
30
31
  /**
32
   * {@inheritdoc}
33
   */
34
  public static function create(ContainerInterface $container, $basePluginId) {
35
    return new static(
36
      $container->get('entity_type.manager'),
37
      $container->get('entity_display.repository')
38
    );
39
  }
40
41
  /**
42
   * EntityRenderedDeriver constructor.
43
   *
44
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
45
   *   The entity type manager service.
46
   * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entityDisplayRepository
47
   *   The entity display repository service.
48
   */
49
  public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityDisplayRepositoryInterface $entityDisplayRepository) {
50
    $this->entityTypeManager = $entityTypeManager;
51
    $this->entityDisplayRepository = $entityDisplayRepository;
52
  }
53
54
  /**
55
   * {@inheritdoc}
56
   */
57
  public function getDerivativeDefinitions($basePluginDefinition) {
58
    foreach ($this->entityTypeManager->getDefinitions() as $id => $type) {
59
      if ($type instanceof ContentEntityTypeInterface && !empty($this->entityDisplayRepository->getViewModes($id))) {
60
        $derivative = [
61
          'parents' => [StringHelper::camelCase($id)],
62
          'description' => $this->t("Renders '@type' entities in the given view mode.", ['@type' => $type->getLabel()]),
63
          'entity_type' => $id,
64
        ] + $basePluginDefinition;
65
66
        if (!isset($derivative['arguments']['mode'])) {
67
          $derivative['arguments'] = isset($derivative['arguments']) ? $derivative['arguments'] : [];
68
          $derivative['arguments']['mode'] = [
69
            'type' => StringHelper::camelCase($id, 'display', 'mode', 'id'),
70
            'optional' => TRUE,
71
          ];
72
        }
73
74
        $this->derivatives["entity:$id"] = $derivative;
0 ignored issues
show
Bug Best Practice introduced by
The property derivatives does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
75
      }
76
    }
77
78
    return parent::getDerivativeDefinitions($basePluginDefinition);
79
  }
80
81
}
82