You are here

protected function RouteSubscriber::getEntityCloneRoute in Entity Clone 8

Gets the entity_clone route.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

Return value

\Symfony\Component\Routing\Route|null The generated route, if available.

1 call to RouteSubscriber::getEntityCloneRoute()
RouteSubscriber::alterRoutes in src/Routing/RouteSubscriber.php
Alters existing routes for a specific collection.

File

src/Routing/RouteSubscriber.php, line 54

Class

RouteSubscriber
Subscriber for Entity Clone routes.

Namespace

Drupal\entity_clone\Routing

Code

protected function getEntityCloneRoute(EntityTypeInterface $entity_type) {
  if ($clone_form = $entity_type
    ->getLinkTemplate('clone-form')) {
    $entity_type_id = $entity_type
      ->id();
    $route = new Route($clone_form);
    $route
      ->addDefaults([
      '_form' => '\\Drupal\\entity_clone\\Form\\EntityCloneForm',
      '_title' => 'Clone ' . $entity_type
        ->getLabel(),
    ])
      ->addRequirements([
      '_entity_access' => $entity_type_id . '.clone',
    ])
      ->setOption('_entity_clone_entity_type_id', $entity_type_id)
      ->setOption('_admin_route', TRUE)
      ->setOption('parameters', [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
      ],
    ]);

    // Special case for menu link content.
    // Menu link content does not work properly with custom operation.
    // This case must be removed when issue #3016038
    // (https://www.drupal.org/project/drupal/issues/3016038) was closed.
    if ($entity_type_id === 'menu_link_content') {
      $route
        ->setRequirements([
        '_permission' => 'clone ' . $entity_type_id . ' entity',
      ]);
    }
    return $route;
  }
}