You are here

protected function Route::alterRoutes in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()
  2. 8.6 modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()
  3. 8.7 modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()
  4. 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()
  5. 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()
  6. 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()
  7. 10.2.x modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php \Drupal\social_group_flexible_group\Subscriber\Route::alterRoutes()

Alters existing routes for a specific collection.

Parameters

\Symfony\Component\Routing\RouteCollection $collection: The route collection for adding routes.

Overrides RouteSubscriberBase::alterRoutes

File

modules/social_features/social_group/modules/social_group_flexible_group/src/Subscriber/Route.php, line 18

Class

Route
Class Route.

Namespace

Drupal\social_group_flexible_group\Subscriber

Code

protected function alterRoutes(RouteCollection $collection) {

  // We define our routes and how they are impacted.
  // is it on content visibility or join method.
  $join_routes = [
    'view.group_manage_members.page_group_manage_members' => 'join direct',
    'entity.group_content.add_form' => 'join added',
  ];
  foreach ($join_routes as $name => $argument) {
    if ($route = $collection
      ->get($name)) {
      $current = $route
        ->getRequirements();
      $requirements = array_merge($current, [
        '_flexible_group_join_permission' => $argument,
      ]);
      $route
        ->addRequirements($requirements);
    }
  }

  // Based on content visibility some routes need access.
  // The argument is there for a minimum content visibility.
  $content_routes = [
    'entity.group.canonical',
    'view.group_information.page_group_about',
    'view.group_members.page_group_members',
    'social_group.stream',
    'view.group_events.page_group_events',
    'view.group_topics.page_group_topics',
  ];

  // Invoke implementations of
  // hook_social_group_flexible_group_content_routes_alter().
  // This to ensure extensions can also add their content tabs.
  \Drupal::moduleHandler()
    ->alter('social_group_flexible_group_content_routes', $content_routes);
  foreach ($content_routes as $name) {
    if ($route = $collection
      ->get($name)) {
      $current = $route
        ->getRequirements();
      $requirements = array_merge($current, [
        '_flexible_group_content_visibility' => 'public',
      ]);
      $route
        ->addRequirements($requirements);
    }
  }
}