Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
50.00% |
6 / 12 |
|
40.00% |
2 / 5 |
|
50.00% |
2 / 4 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| DisplayBuilderRoutes | |
50.00% |
6 / 12 |
|
40.00% |
2 / 5 |
|
50.00% |
2 / 4 |
|
66.67% |
2 / 3 |
6.00 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSubscribedEvents | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| onAlterRoutes | |
25.00% |
2 / 8 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
3.69 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder_views\Routing; |
| 6 | |
| 7 | use Drupal\Core\Routing\RouteBuildEvent; |
| 8 | use Drupal\Core\Routing\RoutingEvents; |
| 9 | use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; |
| 10 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
| 11 | use Symfony\Contracts\Service\ServiceCollectionInterface; |
| 12 | |
| 13 | /** |
| 14 | * Provides routes for the Display Builder Views. |
| 15 | * |
| 16 | * @internal |
| 17 | * Tagged services are internal. |
| 18 | */ |
| 19 | final class DisplayBuilderRoutes implements EventSubscriberInterface { |
| 20 | |
| 21 | /** |
| 22 | * {@inheritdoc} |
| 23 | */ |
| 24 | public function __construct( |
| 25 | #[AutowireLocator('paramconverter')] |
| 26 | private ServiceCollectionInterface $converters, |
| 27 | ) {} |
| 28 | |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | public static function getSubscribedEvents(): array { |
| 33 | return [ |
| 34 | RoutingEvents::ALTER => 'onAlterRoutes', |
| 35 | ]; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Alters existing routes for a specific collection. |
| 40 | * |
| 41 | * @param \Drupal\Core\Routing\RouteBuildEvent $event |
| 42 | * The route build event. |
| 43 | */ |
| 44 | public function onAlterRoutes(RouteBuildEvent $event): void { |
| 45 | // From Drupal 11.3 to Drupal 11.4, converter route parameter has changed. |
| 46 | // The value in routing.yml is now the 11.4 one by default. |
| 47 | // Restore the 11.3 one if the 11.4 is not available. |
| 48 | // @see https://www.drupal.org/project/drupal/issues/3436295 |
| 49 | // @todo Remove once Drupal 11.3 is not supported. |
| 50 | if ($this->converters->has('paramconverter.views_ui')) { |
| 51 | return; |
| 52 | } |
| 53 | /** @var \Symfony\Component\Routing\RouteCollection $collection */ |
| 54 | $collection = $event->getRouteCollection(); |
| 55 | $route = $collection->get('display_builder_views.views.manage'); |
| 56 | $parameters = $route->getOption('parameters'); |
| 57 | $parameters['view']['converter'] = 'drupal.proxy_original_service.paramconverter.views_ui'; |
| 58 | $route->setOption('parameters', $parameters); |
| 59 | $collection->add('display_builder_views.views.manage', $route); |
| 60 | } |
| 61 | |
| 62 | } |
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.
| 26 | private ServiceCollectionInterface $converters, |
| 27 | ) {} |
| 34 | RoutingEvents::ALTER => 'onAlterRoutes', |
| 35 | ]; |
| 36 | } |
| 44 | public function onAlterRoutes(RouteBuildEvent $event): void { |
| 45 | // From Drupal 11.3 to Drupal 11.4, converter route parameter has changed. |
| 46 | // The value in routing.yml is now the 11.4 one by default. |
| 47 | // Restore the 11.3 one if the 11.4 is not available. |
| 48 | // @see https://www.drupal.org/project/drupal/issues/3436295 |
| 49 | // @todo Remove once Drupal 11.3 is not supported. |
| 50 | if ($this->converters->has('paramconverter.views_ui')) { |
| 51 | return; |
| 54 | $collection = $event->getRouteCollection(); |
| 55 | $route = $collection->get('display_builder_views.views.manage'); |
| 56 | $parameters = $route->getOption('parameters'); |
| 57 | $parameters['view']['converter'] = 'drupal.proxy_original_service.paramconverter.views_ui'; |
| 58 | $route->setOption('parameters', $parameters); |
| 59 | $collection->add('display_builder_views.views.manage', $route); |
| 60 | } |