You are here

class TeamAppRouteProvider in Apigee Edge 8

Default entity routes for team apps.

Hierarchy

Expanded class hierarchy of TeamAppRouteProvider

File

modules/apigee_edge_teams/src/Entity/TeamAppRouteProvider.php, line 36

Namespace

Drupal\apigee_edge_teams\Entity
View source
class TeamAppRouteProvider extends AppRouteProvider {
  use TeamRoutingHelperTrait;

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = parent::getRoutes($entity_type);
    $entity_type_id = $entity_type
      ->id();

    /** @var \Symfony\Component\Routing\Route $route */
    foreach ($collection as $route) {
      $this
        ->alterRoutesWithAppName($route);
    }
    if ($add_form_for_team = $this
      ->getAddFormRouteForTeam($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.add_form_for_team", $add_form_for_team);
    }
    if ($collection_by_team = $this
      ->getCollectionRouteByTeam($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.collection_by_team", $collection_by_team);
    }
    if ($api_keys = $this
      ->getTeamApiKeysRoute($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.api_keys", $api_keys);
    }
    if ($add_api_key_form = $this
      ->getAddApiKeyRoute($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.add_api_key_form", $add_api_key_form);
    }
    if ($delete_api_key_form = $this
      ->getDeleteApiKeyRoute($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.delete_api_key_form", $delete_api_key_form);
    }
    if ($revoke_api_key_form = $this
      ->getRevokeApiKeyRoute($entity_type)) {
      $collection
        ->add("entity.{$entity_type_id}.revoke_api_key_form", $revoke_api_key_form);
    }
    return $collection;
  }

  /**
   * {@inheritdoc}
   */
  protected function getCollectionRoute(EntityTypeInterface $entity_type) {
    $route = parent::getCollectionRoute($entity_type);
    if ($route) {
      $requirements = $route
        ->getRequirements();

      // Users with "Manage Team Apps" permission should also have access.
      $permission = TeamAppPermissionProvider::MANAGE_TEAM_APPS_PERMISSION;
      if (isset($requirements['_permission'])) {
        $requirements['_permission'] .= "+{$permission}";
      }
      else {
        $requirements['_permission'] = $permission;
      }
      $route
        ->setRequirements($requirements);
    }
    return $route;
  }

  /**
   * Gets the add-form route for team.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getAddFormRouteForTeam(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('add-form-for-team')) {
      $route = new Route($entity_type
        ->getLinkTemplate('add-form-for-team'));
      $route
        ->setDefault('_entity_form', 'team_app.add_for_team');
      $route
        ->setDefault('_title_callback', AppTitleProvider::class . '::addTitle');
      $route
        ->setDefault('entity_type_id', $entity_type
        ->id());
      $this
        ->ensureTeamParameter($route);
      $route
        ->setRequirement('_entity_create_access', $entity_type
        ->id());
      return $route;
    }
  }

  /**
   * Gets the collection route for a team.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getCollectionRouteByTeam(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('collection-by-team')) {
      $route = new Route($entity_type
        ->getLinkTemplate('collection-by-team'));
      $route
        ->setDefault('_controller', TeamAppListByTeam::class . '::render');
      $route
        ->setDefault('_title_callback', TeamAppListByTeam::class . '::pageTitle');
      $this
        ->ensureTeamParameter($route);
      $route
        ->setRequirement('_apigee_edge_teams_team_app_list_by_team_access', 'TRUE');
      return $route;
    }
  }

  /**
   * Gets APpi Keys for team app.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getTeamApiKeysRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('api-keys')) {
      $route = new Route($entity_type
        ->getLinkTemplate('api-keys'));
      $route
        ->setDefault('_controller', TeamAppKeysController::class . '::teamAppKeys');
      $route
        ->setDefault('_title_callback', AppTitleProvider::class . '::title');
      $this
        ->ensureTeamParameter($route);
      $route
        ->setRequirement('_app_access_check_by_app_name', 'view');
      return $route;
    }
  }

  /**
   * Gets the add-api-key-form route for a team app.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getAddApiKeyRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('add-api-key-form')) {
      $route = new Route($entity_type
        ->getLinkTemplate('add-api-key-form'));
      $route
        ->setDefault('_form', TeamAppApiKeyAddForm::class);
      $route
        ->setDefault('_title', 'Add key');
      $route
        ->setDefault('entity_type_id', $entity_type
        ->id());
      $this
        ->ensureTeamParameter($route);
      $route
        ->setRequirement('_app_access_check_by_app_name', 'add_api_key');
      return $route;
    }
  }

  /**
   * Gets the delete-api-key-form route for a team app.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getDeleteApiKeyRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('delete-api-key-form')) {
      $route = new Route($entity_type
        ->getLinkTemplate('delete-api-key-form'));
      $route
        ->setDefault('_form', TeamAppApiKeyDeleteForm::class);
      $route
        ->setDefault('entity_type_id', $entity_type
        ->id());
      $this
        ->ensureTeamParameter($route);
      $route
        ->setRequirement('_app_access_check_by_app_name', 'delete_api_key');
      return $route;
    }
  }

  /**
   * Gets the revoke-api-key-form route for a team app.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getRevokeApiKeyRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('revoke-api-key-form')) {
      $route = new Route($entity_type
        ->getLinkTemplate('revoke-api-key-form'));
      $route
        ->setDefault('_form', TeamAppApiKeyRevokeForm::class);
      $route
        ->setDefault('entity_type_id', $entity_type
        ->id());
      $this
        ->ensureTeamParameter($route);
      $route
        ->setRequirement('_app_access_check_by_app_name', 'revoke_api_key');
      return $route;
    }
  }

  /**
   * Alters routers with {app} and not {team_app}.
   *
   * @param \Symfony\Component\Routing\Route $route
   *   Route object.
   */
  private function alterRoutesWithAppName(Route $route) : void {
    if (strpos($route
      ->getPath(), '{app}') !== FALSE) {

      // "team_app" parameter must be removed otherwise it cause
      // MissingMandatoryParametersException exceptions.
      $options = $route
        ->getOptions();
      unset($options['parameters']['team_app']);
      $route
        ->setOptions($options);

      // Default access check must be replaced.
      // @see \Drupal\apigee_edge\Access\AppAccessCheckByAppName
      $requirements = $route
        ->getRequirements();
      list(, $operation) = explode('.', $requirements['_entity_access']);
      $requirements['_app_access_check_by_app_name'] = $operation;
      unset($requirements['_entity_access']);
      $route
        ->setRequirements($requirements);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AppRouteProvider::getAnalyticsRoute protected function Gets the analytics route.
DefaultHtmlRouteProvider::$entityFieldManager protected property The entity field manager.
DefaultHtmlRouteProvider::$entityTypeManager protected property The entity type manager.
DefaultHtmlRouteProvider::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance 1
DefaultHtmlRouteProvider::getAddFormRoute protected function Gets the add-form route. 2
DefaultHtmlRouteProvider::getAddPageRoute protected function Gets the add page route. 2
DefaultHtmlRouteProvider::getDeleteMultipleFormRoute protected function Returns the delete multiple form route. 1
DefaultHtmlRouteProvider::getEntityTypeIdKeyType protected function Gets the type of the ID key for a given entity type. 1
DefaultHtmlRouteProvider::__construct public function Constructs a new DefaultHtmlRouteProvider. 1
EdgeEntityRouteProvider::getCanonicalRoute protected function Gets the canonical route. Overrides DefaultHtmlRouteProvider::getCanonicalRoute 1
EdgeEntityRouteProvider::getDeleteFormRoute protected function Gets the delete-form route. Overrides DefaultHtmlRouteProvider::getDeleteFormRoute
EdgeEntityRouteProvider::getEditFormRoute protected function Gets the edit-form route. Overrides DefaultHtmlRouteProvider::getEditFormRoute
TeamAppRouteProvider::alterRoutesWithAppName private function Alters routers with {app} and not {team_app}.
TeamAppRouteProvider::getAddApiKeyRoute protected function Gets the add-api-key-form route for a team app.
TeamAppRouteProvider::getAddFormRouteForTeam protected function Gets the add-form route for team.
TeamAppRouteProvider::getCollectionRoute protected function Gets the collection route. Overrides DefaultHtmlRouteProvider::getCollectionRoute
TeamAppRouteProvider::getCollectionRouteByTeam protected function Gets the collection route for a team.
TeamAppRouteProvider::getDeleteApiKeyRoute protected function Gets the delete-api-key-form route for a team app.
TeamAppRouteProvider::getRevokeApiKeyRoute protected function Gets the revoke-api-key-form route for a team app.
TeamAppRouteProvider::getRoutes public function Provides routes for entities. Overrides AppRouteProvider::getRoutes
TeamAppRouteProvider::getTeamApiKeysRoute protected function Gets APpi Keys for team app.
TeamRoutingHelperTrait::ensureTeamParameter private function If route contains the {team} parameter add required changes to the route.