Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / src / Routing / DeleteMultipleRouteProvider.php
1 <?php
2
3 namespace Drupal\entity\Routing;
4
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Entity\Routing\EntityRouteProviderInterface;
7 use Symfony\Component\Routing\Route;
8 use Symfony\Component\Routing\RouteCollection;
9
10 /**
11  * Provides the HTML route for deleting multiple entities.
12  *
13  * @deprecated Since Drupal 8.6.x the core DefaultHtmlRouteProvider provides
14  *   the route for any entity type with a "delete-multiple-form" link template
15  *   and a "delete-multiple-confirm" form.
16  */
17 class DeleteMultipleRouteProvider implements EntityRouteProviderInterface {
18
19   /**
20    * {@inheritdoc}
21    */
22   public function getRoutes(EntityTypeInterface $entity_type) {
23     $routes = new RouteCollection();
24     if ($route = $this->deleteMultipleFormRoute($entity_type)) {
25       $routes->add('entity.' . $entity_type->id() . '.delete_multiple_form', $route);
26     }
27
28     return $routes;
29   }
30
31   /**
32    * Returns the delete multiple form route.
33    *
34    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
35    *   The entity type.
36    *
37    * @return \Symfony\Component\Routing\Route|null
38    *   The generated route, if available.
39    */
40   protected function deleteMultipleFormRoute(EntityTypeInterface $entity_type) {
41     // Core requires a "delete-multiple-confirm" form to be declared as well,
42     // if it's missing, it's safe to assume that the entity type is still
43     // relying on previous Entity API contrib behavior.
44     if ($entity_type->hasLinkTemplate('delete-multiple-form') && !$entity_type->hasHandlerClass('form', 'delete-multiple-confirm')) {
45       $route = new Route($entity_type->getLinkTemplate('delete-multiple-form'));
46       $route->setDefault('_form', '\Drupal\entity\Form\DeleteMultipleForm');
47       $route->setDefault('entity_type_id', $entity_type->id());
48       $route->setRequirement('_entity_delete_multiple_access', $entity_type->id());
49
50       return $route;
51     }
52   }
53
54 }