Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ProfileRouteProvider | |
0.00% |
0 / 25 |
|
0.00% |
0 / 11 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| getRoutes | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getEditPluginFormRoute | |
0.00% |
0 / 20 |
|
0.00% |
0 / 8 |
|
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Drupal\display_builder\Routing; |
| 6 | |
| 7 | use Drupal\Core\Entity\EntityTypeInterface; |
| 8 | use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; |
| 9 | use Symfony\Component\Routing\Route; |
| 10 | |
| 11 | /** |
| 12 | * Provides routes for display builder entities. |
| 13 | */ |
| 14 | class ProfileRouteProvider extends AdminHtmlRouteProvider { |
| 15 | |
| 16 | /** |
| 17 | * {@inheritdoc} |
| 18 | */ |
| 19 | public function getRoutes(EntityTypeInterface $entity_type) { |
| 20 | $collection = parent::getRoutes($entity_type); |
| 21 | $entity_type_id = $entity_type->id(); |
| 22 | |
| 23 | if ($add_page_route = $this->getEditPluginFormRoute($entity_type)) { |
| 24 | $collection->add("entity.{$entity_type_id}.edit_plugin_form", $add_page_route); |
| 25 | } |
| 26 | |
| 27 | return $collection; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Gets the edit-plugin-form route. |
| 32 | * |
| 33 | * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type |
| 34 | * The entity type. |
| 35 | * |
| 36 | * @return \Symfony\Component\Routing\Route|null |
| 37 | * The generated route, if available. |
| 38 | */ |
| 39 | protected function getEditPluginFormRoute(EntityTypeInterface $entity_type): ?Route { |
| 40 | if ($entity_type->hasLinkTemplate('edit-plugin-form') |
| 41 | && \is_string($entity_type->getLinkTemplate('edit-plugin-form'))) { |
| 42 | $entity_type_id = $entity_type->id(); |
| 43 | $route = new Route($entity_type->getLinkTemplate('edit-plugin-form')); |
| 44 | // Use the edit form handler, if available, otherwise default. |
| 45 | $operation = 'default'; |
| 46 | |
| 47 | if ($entity_type->getFormClass('edit-plugin')) { |
| 48 | $operation = 'edit-plugin'; |
| 49 | } |
| 50 | $route |
| 51 | ->setDefaults([ |
| 52 | '_entity_form' => "{$entity_type_id}.{$operation}", |
| 53 | '_title_callback' => '\Drupal\display_builder\Form\ProfileIslandPluginForm::editFormTitle', |
| 54 | ]) |
| 55 | ->setRequirement('_entity_access', "{$entity_type_id}.update") |
| 56 | ->setOption('parameters', [ |
| 57 | $entity_type_id => ['type' => 'entity:' . $entity_type_id], |
| 58 | ]); |
| 59 | |
| 60 | // Entity types with serial IDs can specify this in their route |
| 61 | // requirements, improving the matching process. |
| 62 | if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') { |
| 63 | $route->setRequirement($entity_type_id, '\d+'); |
| 64 | } |
| 65 | |
| 66 | return $route; |
| 67 | } |
| 68 | |
| 69 | return NULL; |
| 70 | } |
| 71 | |
| 72 | } |