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(
25    protected RouteProviderInterface $routeProvider,
26    protected ComponentPluginManager $componentPluginManager,
27    protected EntityTypeManagerInterface $entityTypeManager,
28    TranslationInterface $stringTranslation,
29  ) {
30    $this->setStringTranslation($stringTranslation);
31  }
32
33  /**
34   * {@inheritdoc}
35   */
36  public static function create(ContainerInterface $container, $base_plugin_id): static {
37    return new static(
38      $container->get('router.route_provider'),
39      $container->get('plugin.manager.sdc'),
40      $container->get('entity_type.manager'),
41      $container->get('string_translation')
42    );
43  }
44
45  /**
46   * {@inheritdoc}
47   */
48  public function getDerivativeDefinitions($base_plugin_definition): array {
49    $this->derivatives = [];
50    $display_infos = EntityViewDisplay::getDisplayInfos($this->entityTypeManager);
51
52    foreach ($display_infos as $entity_type_id => $display_info) {
53      $forward = \sprintf('entity.%s.display_builder.forward', $entity_type_id);
54      // We add the "Display" tab alongside View, Edit, Delete, Revisions...
55      $this->derivatives[$forward] = [
56        'route_name' => $forward,
57        'base_route' => \sprintf('entity.%s.canonical', $entity_type_id),
58        'title' => \count($display_info['modes']) === 1 ? $this->t(':display display', [':display' => \reset($display_info['modes'])]) : $this->t('Display'),
59        // In-between 'Edit' and 'Delete'.
60        'weight' => 10,
61      ];
62
63      // Second level: each tab is a display override.
64      $parent_id = \sprintf('display_builder_entity_view.display_builder_tabs:entity.%s.display_builder.forward', $entity_type_id);
65
66      foreach ($display_info['modes'] as $view_mode => $view_mode_label) {
67        $route = \sprintf('entity.%s.display_builder.%s', $entity_type_id, $view_mode);
68        $this->derivatives[$route] = [
69          'route_name' => $route,
70          'base_route' => $forward,
71          'title' => $view_mode_label,
72          'parent_id' => $parent_id,
73        ];
74      }
75    }
76
77    return $this->derivatives;
78  }
79
80}