Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
EntityViewController | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
title | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
getBuilder | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getEntityViewDisplay | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Drupal\display_builder_entity_view\Controller; |
6 | |
7 | use Drupal\Core\Routing\RouteMatchInterface; |
8 | use Drupal\Core\StringTranslation\TranslatableMarkup; |
9 | use Drupal\display_builder\Controller\IntegrationControllerBase; |
10 | use Drupal\display_builder\DisplayBuildableInterface; |
11 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
12 | |
13 | /** |
14 | * Defines a controller to get access the Display Builder admin UI. |
15 | * |
16 | * @internal |
17 | * Controller classes are internal. |
18 | */ |
19 | final class EntityViewController extends IntegrationControllerBase { |
20 | |
21 | /** |
22 | * Provides a generic title callback for a display used in entities. |
23 | * |
24 | * @param \Drupal\Core\Routing\RouteMatchInterface $route_match |
25 | * The route match object. |
26 | * |
27 | * @return \Drupal\Core\StringTranslation\TranslatableMarkup |
28 | * The title for the display page. |
29 | */ |
30 | public function title(RouteMatchInterface $route_match): TranslatableMarkup { |
31 | $param = [ |
32 | '@bundle' => \ucfirst($route_match->getParameter('bundle')), |
33 | '@view_mode_name' => $route_match->getParameter('view_mode_name'), |
34 | ]; |
35 | |
36 | return $this->t('Display builder for @bundle, @view_mode_name', $param); |
37 | } |
38 | |
39 | /** |
40 | * Renders the Layout UI. |
41 | * |
42 | * @param \Drupal\Core\Routing\RouteMatchInterface $route_match |
43 | * The route match object. |
44 | * |
45 | * @return array |
46 | * A render array. |
47 | */ |
48 | public function getBuilder(RouteMatchInterface $route_match): array { |
49 | // Builder is on the front theme, render cache is too hard and changes are |
50 | // not working with cache (move something and refresh, previous version |
51 | // will be shown). |
52 | // @todo evaluate with #3529284 |
53 | \Drupal::service('page_cache_kill_switch')->trigger(); // phpcs:ignore |
54 | |
55 | $entity_type_id = $route_match->getParameter('entity_type_id'); |
56 | $bundle = $route_match->getParameter('bundle'); |
57 | $view_mode = $route_match->getParameter('view_mode_name'); |
58 | |
59 | $entity_display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode); |
60 | |
61 | if (!$entity_display) { |
62 | // No entity view display. |
63 | throw new NotFoundHttpException(); |
64 | } |
65 | |
66 | return $this->renderBuilder($entity_display); |
67 | } |
68 | |
69 | /** |
70 | * Get entity view display entity. |
71 | * |
72 | * @param string $entity_type_id |
73 | * Entity type ID. |
74 | * @param string $bundle |
75 | * Fieldable entity's bundle. |
76 | * @param string $view_mode |
77 | * View mode of the display. |
78 | * |
79 | * @return \Drupal\display_builder\DisplayBuildableInterface|null |
80 | * The corresponding entity view display. |
81 | */ |
82 | protected function getEntityViewDisplay(string $entity_type_id, string $bundle, string $view_mode): ?DisplayBuildableInterface { |
83 | $display_id = "{$entity_type_id}.{$bundle}.{$view_mode}"; |
84 | |
85 | /** @var \Drupal\display_builder\DisplayBuildableInterface|null $display */ |
86 | $display = $this->entityTypeManager()->getStorage('entity_view_display') |
87 | ->load($display_id); |
88 | |
89 | return $display; |
90 | } |
91 | |
92 | } |