You are here

protected function ConnectionHtmlRouteProvider::getAddEntityRoutes in RedHen CRM 8

Gets all entity type add connection routes.

Parameters

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

Return value

array An array of routes keyed with "form" and "add", if available.

1 call to ConnectionHtmlRouteProvider::getAddEntityRoutes()
ConnectionHtmlRouteProvider::getRoutes in modules/redhen_connection/src/ConnectionHtmlRouteProvider.php
Provides routes for entities.

File

modules/redhen_connection/src/ConnectionHtmlRouteProvider.php, line 118

Class

ConnectionHtmlRouteProvider
Provides routes for Connection entities.

Namespace

Drupal\redhen_connection

Code

protected function getAddEntityRoutes(EntityTypeInterface $connection_entity_type) {
  $routes = [];
  $connection_entity_type_id = $connection_entity_type
    ->id();
  $service = \Drupal::service('redhen_connection.connections');
  $entity_types = $service
    ->getAllConnectionEntityTypes();

  // Iterate over each entity type to find connectable entities.
  foreach ($entity_types as $type) {
    if ($canonical = $type
      ->getLinkTemplate('canonical')) {
      $type_id = $type
        ->id();

      // Skip over redhen_connection entity types.
      if ($type_id == 'redhen_connection_type' || $type_id == 'redhen_connection_role') {
        continue;
      }

      // Build route parameters.
      $parameters = [
        $type_id => [
          'type' => 'entity:' . $type_id,
        ],
      ];
      $route[$type_id] = [];

      // Add both form and add routes to routes array.
      foreach ([
        'form',
        'add',
      ] as $route_type) {

        // Set specific values for form routes.
        if ($route_type === 'form') {
          $path = '/connection/add/{redhen_connection_type}';
          $parameters[$connection_entity_type_id] = [
            'type' => 'entity:' . $connection_entity_type_id,
          ];
          $controller = 'Drupal\\redhen_connection\\Controller\\ConnectionAddController::addForm';
          $title_callback = 'Drupal\\redhen_connection\\Controller\\ConnectionAddController::getAddFormTitle';
          $routes[$type_id]['form'] = $this
            ->generateRoute($canonical, $path, $parameters, $controller, $title_callback, $connection_entity_type_id);
        }
        else {
          $path = "/connection/add";
          $controller = 'Drupal\\redhen_connection\\Controller\\ConnectionAddController::add';
          $title_callback = 'Drupal\\redhen_connection\\Controller\\ConnectionAddController::getAddTitle';
          $routes[$type_id]['add'] = $this
            ->generateRoute($canonical, $path, $parameters, $controller, $title_callback, $connection_entity_type_id);
        }
      }
    }
  }
  return $routes;
}