You are here

class EntityFlagActionRouteProvider in farmOS 2.x

Provides routes for the entity flag action.

Hierarchy

Expanded class hierarchy of EntityFlagActionRouteProvider

1 file declares its use of EntityFlagActionRouteProvider
farm_flag.module in modules/core/flag/farm_flag.module
The farmOS Flags module.

File

modules/core/flag/src/Routing/EntityFlagActionRouteProvider.php, line 13

Namespace

Drupal\farm_flag\Routing
View source
class EntityFlagActionRouteProvider implements EntityRouteProviderInterface {

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = new RouteCollection();
    $entity_type_id = $entity_type
      ->id();
    if ($flag_route = $this
      ->getEntityFlagFormRoute($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.flag_form", $flag_route);
    }
    return $collection;
  }

  /**
   * Gets the entity flag form route.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getEntityFlagFormRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('flag-action-form')) {
      $route = new Route($entity_type
        ->getLinkTemplate('flag-action-form'));
      $route
        ->setDefault('_form', $entity_type
        ->getFormClass('flag-action-form'));
      $route
        ->setDefault('entity_type_id', $entity_type
        ->id());
      $route
        ->setRequirement('_user_is_logged_in', 'TRUE');
      return $route;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityFlagActionRouteProvider::getEntityFlagFormRoute protected function Gets the entity flag form route.
EntityFlagActionRouteProvider::getRoutes public function Provides routes for entities. Overrides EntityRouteProviderInterface::getRoutes