Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| IntegrationControllerBase | |
0.00% |
0 / 10 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| renderBuilder | |
0.00% |
0 / 9 |
|
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder\Controller; |
| 6 | |
| 7 | use Drupal\Core\Controller\ControllerBase; |
| 8 | use Drupal\Core\DependencyInjection\AutowireTrait; |
| 9 | use Drupal\display_builder\DisplayBuildableInterface; |
| 10 | use Drupal\display_builder\DisplayBuildablePluginManager; |
| 11 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
| 12 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
| 13 | |
| 14 | /** |
| 15 | * Shared logic between integrations controllers. |
| 16 | */ |
| 17 | abstract class IntegrationControllerBase extends ControllerBase { |
| 18 | |
| 19 | use AutowireTrait; |
| 20 | |
| 21 | /** |
| 22 | * {@inheritdoc} |
| 23 | */ |
| 24 | public function __construct( |
| 25 | protected DisplayBuildablePluginManager $displayBuildableManager, |
| 26 | ) {} |
| 27 | |
| 28 | /** |
| 29 | * Render a Display Builder profile entity view. |
| 30 | * |
| 31 | * @param \Drupal\display_builder\DisplayBuildableInterface $buildable |
| 32 | * The integration using the display builder. |
| 33 | * |
| 34 | * @return array |
| 35 | * A renderable array |
| 36 | */ |
| 37 | protected function renderBuilder(DisplayBuildableInterface $buildable): array { |
| 38 | /** @var \Drupal\display_builder\ProfileInterface $profile */ |
| 39 | $profile = $buildable->getProfile(); |
| 40 | |
| 41 | if (!$profile) { |
| 42 | throw new NotFoundHttpException(); |
| 43 | } |
| 44 | |
| 45 | if (!$profile->access('view')) { |
| 46 | throw new AccessDeniedHttpException(); |
| 47 | } |
| 48 | |
| 49 | $instance_id = $buildable->getInstanceId(); |
| 50 | $buildable->initInstanceIfMissing(); |
| 51 | $view_builder = $this->entityTypeManager()->getViewBuilder('display_builder_profile'); |
| 52 | |
| 53 | return $view_builder->view($profile, $instance_id); |
| 54 | } |
| 55 | |
| 56 | } |