You are here

class DiffRouteProvider in Diff 8

Contains routes for diff functionality.

Hierarchy

Expanded class hierarchy of DiffRouteProvider

1 file declares its use of DiffRouteProvider
diff_test.module in tests/modules/diff_test/diff_test.module
Helper module for the diff tests.

File

src/Routing/DiffRouteProvider.php, line 13

Namespace

Drupal\diff\Routing
View source
class DiffRouteProvider implements EntityRouteProviderInterface {

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = new RouteCollection();
    if ($route = $this
      ->getDiffRoute($entity_type)) {
      $collection
        ->add('entity.' . $entity_type
        ->id() . '.revisions_diff', $route);
    }
    return $collection;
  }

  /**
   * Constructs the diff route.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The diff route.
   */
  protected function getDiffRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('revisions-diff')) {
      $route = new Route($entity_type
        ->getLinkTemplate('revisions-diff'));
      $route
        ->addDefaults([
        '_controller' => '\\Drupal\\diff\\Controller\\PluginRevisionController::compareEntityRevisions',
        'filter' => 'split_fields',
      ]);
      $route
        ->addRequirements([
        '_entity_access' => $entity_type
          ->id() . '.view',
      ]);
      $route
        ->setOption('parameters', [
        $entity_type
          ->id() => [
          'type' => 'entity:' . $entity_type
            ->id(),
        ],
        'left_revision' => [
          'type' => 'entity_revision:' . $entity_type
            ->id(),
        ],
        'right_revision' => [
          'type' => 'entity_revision:' . $entity_type
            ->id(),
        ],
      ]);
      return $route;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DiffRouteProvider::getDiffRoute protected function Constructs the diff route.
DiffRouteProvider::getRoutes public function Provides routes for entities. Overrides EntityRouteProviderInterface::getRoutes