You are here

class ApiDocHtmlRouteProvider in Apigee API Catalog 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Routing/ApiDocHtmlRouteProvider.php \Drupal\apigee_api_catalog\Entity\Routing\ApiDocHtmlRouteProvider

Provides routes for API Doc entities.

Hierarchy

Expanded class hierarchy of ApiDocHtmlRouteProvider

See also

\Drupal\Core\Entity\Routing\AdminHtmlRouteProvider

\Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider

File

src/Entity/Routing/ApiDocHtmlRouteProvider.php, line 35

Namespace

Drupal\apigee_api_catalog\Entity\Routing
View source
class ApiDocHtmlRouteProvider extends AdminHtmlRouteProvider {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = parent::getRoutes($entity_type);
    if ($settings_form_route = $this
      ->getSettingsFormRoute($entity_type)) {
      $collection
        ->add('entity.apidoc.settings', $settings_form_route);
    }
    if ($apidoc_collection_route = $collection
      ->get('entity.apidoc.collection')) {
      $apidoc_collection_route
        ->setDefault('_title', $this
        ->t('@entity_type catalog', [
        '@entity_type' => $entity_type
          ->getLabel(),
      ])
        ->render());
    }
    if ($reimport_spec_route = $this
      ->getReimportSpecFormRoute($entity_type)) {
      $collection
        ->add("entity.apidoc.reimport_spec_form", $reimport_spec_route);
    }
    return $collection;
  }

  /**
   * Gets the settings 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 getSettingsFormRoute(EntityTypeInterface $entity_type) {
    if (!$entity_type
      ->getBundleEntityType()) {
      $route = new Route('admin/structure/apidoc');
      $route
        ->setDefaults([
        '_form' => 'Drupal\\apigee_api_catalog\\Entity\\Form\\ApiDocSettingsForm',
        '_title_callback' => ApiDocController::class . '::title',
      ])
        ->setRequirement('_permission', $entity_type
        ->getAdminPermission())
        ->setOption('_admin_route', TRUE);
      return $route;
    }
  }

  /**
   * Gets the reimport-spec-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 getReimportSpecFormRoute(EntityTypeInterface $entity_type) {
    $route = new Route($entity_type
      ->getLinkTemplate('reimport-spec-form'));
    $route
      ->setDefaults([
      '_entity_form' => "apidoc.reimport_spec",
      '_title' => 'Re-import API Doc OpenAPI specification',
    ])
      ->setRequirement('_entity_access', "apidoc.reimport")
      ->setOption('parameters', [
      'apidoc' => [
        'type' => 'entity:apidoc',
      ],
    ]);

    // Entity types with serial IDs can specify this in their route
    // requirements, improving the matching process.
    if ($this
      ->getEntityTypeIdKeyType($entity_type) === 'integer') {
      $route
        ->setRequirement('apidoc', '\\d+');
    }
    return $route;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdminHtmlRouteProvider::getAddFormRoute protected function Gets the add-form route. Overrides DefaultHtmlRouteProvider::getAddFormRoute
AdminHtmlRouteProvider::getAddPageRoute protected function Gets the add page route. Overrides DefaultHtmlRouteProvider::getAddPageRoute
AdminHtmlRouteProvider::getDeleteFormRoute protected function Gets the delete-form route. Overrides DefaultHtmlRouteProvider::getDeleteFormRoute
AdminHtmlRouteProvider::getDeleteMultipleFormRoute protected function Returns the delete multiple form route. Overrides DefaultHtmlRouteProvider::getDeleteMultipleFormRoute
AdminHtmlRouteProvider::getEditFormRoute protected function Gets the edit-form route. Overrides DefaultHtmlRouteProvider::getEditFormRoute 1
ApiDocHtmlRouteProvider::getReimportSpecFormRoute protected function Gets the reimport-spec-form route.
ApiDocHtmlRouteProvider::getRoutes public function Provides routes for entities. Overrides DefaultHtmlRouteProvider::getRoutes
ApiDocHtmlRouteProvider::getSettingsFormRoute protected function Gets the settings form 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::getCanonicalRoute protected function Gets the canonical route. 3
DefaultHtmlRouteProvider::getCollectionRoute protected function Gets the collection route. 2
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
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.