Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
EntityOverrideViewLocalTask
0.00% covered (danger)
0.00%
0 / 27
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 6
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 getDerivativeDefinitions
0.00% covered (danger)
0.00%
0 / 20
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder_entity_view\Plugin\Derivative;
6
7use Drupal\Component\Plugin\Derivative\DeriverBase;
8use Drupal\Core\Entity\EntityTypeManagerInterface;
9use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
10use Drupal\Core\Routing\RouteProviderInterface;
11use Drupal\Core\StringTranslation\StringTranslationTrait;
12use Drupal\Core\StringTranslation\TranslationInterface;
13use Drupal\Core\Theme\ComponentPluginManager;
14use Drupal\display_builder_entity_view\Entity\EntityViewDisplay;
15use Symfony\Component\DependencyInjection\ContainerInterface;
16
17/**
18 * Provides local task definitions for all component forms.
19 */
20class EntityOverrideViewLocalTask extends DeriverBase implements ContainerDeriverInterface {
21
22  use StringTranslationTrait;
23
24  public function __construct(protected RouteProviderInterface $routeProvider, protected ComponentPluginManager $componentPluginManager, protected EntityTypeManagerInterface $entityTypeManager, TranslationInterface $stringTranslation) {
25    $this->setStringTranslation($stringTranslation);
26  }
27
28  /**
29   * {@inheritdoc}
30   */
31  public static function create(ContainerInterface $container, $base_plugin_id): static {
32    return new static(
33      $container->get('router.route_provider'),
34      $container->get('plugin.manager.sdc'),
35      $container->get('entity_type.manager'),
36      $container->get('string_translation')
37    );
38  }
39
40  /**
41   * {@inheritdoc}
42   */
43  public function getDerivativeDefinitions($base_plugin_definition): array {
44    $this->derivatives = [];
45    $display_infos = EntityViewDisplay::getDisplayInfos($this->entityTypeManager);
46
47    foreach ($display_infos as $entity_type_id => $display_info) {
48      $forward = \sprintf('entity.%s.display_builder.forward', $entity_type_id);
49      // We add the "Display" tab alongside View, Edit, Delete, Revisions...
50      $this->derivatives[$forward] = [
51        'route_name' => $forward,
52        'base_route' => \sprintf('entity.%s.canonical', $entity_type_id),
53        'title' => \count($display_info['modes']) === 1 ? $this->t(':display display', [':display' => \reset($display_info['modes'])]) : $this->t('Display'),
54        // In-between 'Edit' and 'Delete'.
55        'weight' => 10,
56      ];
57
58      // Second level: each tab is a display override.
59      $parent_id = \sprintf('display_builder_entity_view.display_builder_tabs:entity.%s.display_builder.forward', $entity_type_id);
60
61      foreach ($display_info['modes'] as $view_mode => $view_mode_label) {
62        $route = \sprintf('entity.%s.display_builder.%s', $entity_type_id, $view_mode);
63        $this->derivatives[$route] = [
64          'route_name' => $route,
65          'base_route' => $forward,
66          'title' => $view_mode_label,
67          'parent_id' => $parent_id,
68        ];
69      }
70    }
71
72    return $this->derivatives;
73  }
74
75}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.