Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 16 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
||
| EntityViewController | |
0.00% |
0 / 16 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
||
| title | |
0.00% |
0 / 5 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
2 | |||||
| getBuilder | |
0.00% |
0 / 7 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
0.00% |
0 / 1 |
6 | |||||
| getEntityViewDisplay | |
0.00% |
0 / 4 |
n/a |
0 / 0 |
n/a |
0 / 0 |
|
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 | $entity_type_id = $route_match->getParameter('entity_type_id'); |
| 50 | $bundle = $route_match->getParameter('bundle'); |
| 51 | $view_mode = $route_match->getParameter('view_mode_name'); |
| 52 | |
| 53 | $entity_display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode); |
| 54 | |
| 55 | if (!$entity_display) { |
| 56 | // No entity view display. |
| 57 | throw new NotFoundHttpException(); |
| 58 | } |
| 59 | |
| 60 | return $this->renderBuilder($entity_display); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get entity view display entity. |
| 65 | * |
| 66 | * @param string $entity_type_id |
| 67 | * Entity type ID. |
| 68 | * @param string $bundle |
| 69 | * Fieldable entity's bundle. |
| 70 | * @param string $view_mode |
| 71 | * View mode of the display. |
| 72 | * |
| 73 | * @return \Drupal\display_builder\DisplayBuildableInterface|null |
| 74 | * The corresponding entity view display. |
| 75 | */ |
| 76 | protected function getEntityViewDisplay(string $entity_type_id, string $bundle, string $view_mode): ?DisplayBuildableInterface { |
| 77 | $display_id = "{$entity_type_id}.{$bundle}.{$view_mode}"; |
| 78 | |
| 79 | /** @var \Drupal\display_builder\DisplayBuildableInterface|null $display */ |
| 80 | $display = $this->entityTypeManager()->getStorage('entity_view_display') |
| 81 | ->load($display_id); |
| 82 | |
| 83 | return $display; |
| 84 | } |
| 85 | |
| 86 | } |