protected function revisionDeleteRoute(EntityTypeInterface $entity_type)
 {
     $route = new Route($entity_type->getLinkTemplate('revision-delete'));
     $route->setDefault('_form', 'Drupal\\content_entity_base\\Entity\\Form\\EntityRevisionDeleteForm');
     $route->setDefault('_title', 'Delete earlier revision');
     $route->setRequirement('_entity_access_revision', $entity_type->id() . '.delete');
     $route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
     return $route;
 }
Example #2
0
 /**
  * Gets the devel load route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getRdfExportRoute(EntityTypeInterface $entity_type)
 {
     if ($rdf_export = $entity_type->getLinkTemplate('rdf-export')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($rdf_export);
         $route->addDefaults(['_controller' => '\\Drupal\\rdf_export\\Controller\\RdfExportController::downloadLinks', '_title' => 'Export RDF Metadata'])->addRequirements(['_permission' => 'export rdf metadata'])->setOption('entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
         return $route;
     }
 }
 /**
  * Gets the devel render route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getDevelRenderRoute(EntityTypeInterface $entity_type)
 {
     if ($devel_render = $entity_type->getLinkTemplate('devel-render')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($devel_render);
         $route->addDefaults(['_controller' => '\\Drupal\\devel\\Controller\\DevelController::entityRender', '_title' => 'Devel Render'])->addRequirements(['_permission' => 'access devel information'])->setOption('_admin_route', TRUE)->setOption('_devel_entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
         return $route;
     }
 }
 /**
  * Gets the moderation-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 getModerationFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('moderation-form') && $entity_type->getFormClass('moderation')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('moderation-form'));
         $route->setDefaults(['_entity_form' => "{$entity_type_id}.moderation", '_title' => 'Moderation'])->setRequirement('_permission', 'administer moderation states')->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
         return $route;
     }
 }
 protected function addPageRoute(EntityTypeInterface $entity_type)
 {
     $route = new Route($entity_type->getLinkTemplate('add-page'));
     $route->setDefault('_controller', '\\Drupal\\content_entity_base\\Entity\\Controller\\EntityBaseController::addPage');
     $route->setDefault('_title_callback', '\\Drupal\\content_entity_base\\Entity\\Controller\\EntityBaseController::getAddPageTitle');
     $route->setDefault('entity_definition', $entity_type->id());
     $route->setOption('parameters', ['entity_definition' => ['type' => 'entity_definition']]);
     $route->setRequirement('_entity_create_access', $entity_type->id());
     return $route;
 }
Example #6
0
 /**
  * Gets the devel load route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getRdfGraphRoute(EntityTypeInterface $entity_type, $graph_definition)
 {
     if ($rdf_draft = $entity_type->getLinkTemplate('rdf-draft-' . $graph_definition['name'])) {
         $entity_type_id = $entity_type->id();
         $route = new Route($rdf_draft);
         $route->addDefaults(['_controller' => '\\Drupal\\rdf_draft\\Controller\\RdfController::view', '_title' => (string) t('View @title', ['@title' => (string) $graph_definition['title']])])->addRequirements(['_access_rdf_graph' => 'TRUE'])->setOption('entity_type_id', $entity_type_id)->setOption('graph_name', $graph_definition['name'])->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
         return $route;
     }
     return NULL;
 }
 /**
  * Returns the delete multiple 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 deleteMultipleFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('delete-multiple-form')) {
         $route = new Route($entity_type->getLinkTemplate('delete-multiple-form'));
         $route->setDefault('_form', '\\Drupal\\entity\\Form\\DeleteMultiple');
         $route->setDefault('entity_type_id', $entity_type->id());
         $route->setRequirement('_permission', $entity_type->getAdminPermission());
         return $route;
     }
 }
 /**
  * Gets the entity revision view route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getRevisionViewRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('revision')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('revision'));
         $route->addDefaults(['_controller' => '\\Drupal\\entity\\Controller\\RevisionController::view', '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title']);
         $route->addRequirements(['_entity_access_revision' => "{$entity_type_id}.view"]);
         $route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()], $entity_type->id() . '_revision' => ['type' => 'entity_revision:' . $entity_type->id()]]);
         return $route;
     }
 }
 /**
  * Returns the add 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 addFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('add-form')) {
         $route = new Route($entity_type->getLinkTemplate('add-form'));
         $route->setDefault('_controller', '\\Drupal\\entity\\Controller\\EntityCreateController::addForm');
         $route->setDefault('_title_callback', '\\Drupal\\entity\\Controller\\EntityCreateController::addFormTitle');
         $route->setDefault('entity_type_id', $entity_type->id());
         $route->setRequirement('_entity_create_access', $entity_type->id());
         return $route;
     }
 }
 /**
  * Gets the add-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 getAddFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('add-form')) {
         $entity_type_id = $entity_type->id();
         $parameters = [$entity_type_id => ['type' => 'entity:' . $entity_type_id]];
         $route = new Route($entity_type->getLinkTemplate('add-form'));
         $bundle_entity_type_id = $entity_type->getBundleEntityType();
         // Content entities with bundles are added via a dedicated controller.
         $route->setDefaults(['_controller' => 'Drupal\\drupalbristol_sponsors\\Controller\\SponsorEntityAddController::addForm', '_title_callback' => 'Drupal\\drupalbristol_sponsors\\Controller\\SponsorEntityAddController::getAddFormTitle'])->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_entity_type_id . '}');
         $parameters[$bundle_entity_type_id] = ['type' => 'entity:' . $bundle_entity_type_id];
         $route->setOption('parameters', $parameters)->setOption('_admin_route', TRUE);
         return $route;
     }
 }
 /**
  * Gets the moderation-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 getLatestVersionRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('latest-version') && $entity_type->hasViewBuilderClass()) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('latest-version'));
         $route->addDefaults(['_entity_view' => "{$entity_type_id}.full", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title'])->setRequirement('_entity_access', "{$entity_type_id}.view")->setRequirement('_permission', 'view latest version,view any unpublished content')->setRequirement('_content_moderation_latest_version', 'TRUE')->setOption('_content_moderation_entity_type', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id, 'load_forward_revision' => 1]]);
         // Entity types with serial IDs can specify this in their route
         // requirements, improving the matching process.
         if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
             $route->setRequirement($entity_type_id, '\\d+');
         }
         return $route;
     }
 }
 /**
  * Gets the add-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 getAddFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('add-form')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('add-form'));
         // Use the add form handler, if available, otherwise default.
         $operation = 'default';
         if ($entity_type->getFormClass('add')) {
             $operation = 'add';
         }
         $route->setDefaults(['_entity_form' => "{$entity_type_id}.{$operation}", '_title' => "Add {$entity_type->getLabel()}"])->setRequirement('_entity_create_access', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]])->setOption('_admin_route', TRUE);
         return $route;
     }
 }
Example #13
0
  /**
   * Gets the entity_clone route.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getEntityCloneRoute(EntityTypeInterface $entity_type) {
    if ($clone_form = $entity_type->getLinkTemplate('clone-form')) {
      $entity_type_id = $entity_type->id();
      $route = new Route($clone_form);
      $route
        ->addDefaults([
          '_form' => '\Drupal\entity_clone\Form\EntityCloneForm',
          '_title' => 'Clone ' . $entity_type->getLabel(),
        ])
        ->addRequirements([
          '_permission' => 'clone ' . $entity_type->id() . ' entity',
        ])
        ->setOption('_entity_clone_entity_type_id', $entity_type_id)
        ->setOption('_admin_route', TRUE)
        ->setOption('parameters', [
          $entity_type_id => ['type' => 'entity:' . $entity_type_id],
        ]);

      return $route;
    }
  }
 /**
  * Gets the add-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 getAddFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('add-form')) {
         $entity_type_id = $entity_type->id();
         $parameters = [$entity_type_id => ['type' => 'entity:' . $entity_type_id]];
         $route = new Route($entity_type->getLinkTemplate('add-form'));
         // Content entities with bundles are added via a dedicated controller.
         if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
             $route->setDefaults(['_controller' => 'Drupal\\custom_page\\Controller\\CustomPageAddController::addForm', '_title_callback' => 'Drupal\\custom_page\\Controller\\CustomPageAddController::getAddFormTitle'])->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_entity_type_id . '}');
             $parameters[$bundle_entity_type_id] = ['type' => 'entity:' . $bundle_entity_type_id];
         } else {
             // Use the add form handler, if available, otherwise default.
             $operation = 'default';
             if ($entity_type->getFormClass('add')) {
                 $operation = 'add';
             }
             $route->setDefaults(['_entity_form' => "{$entity_type_id}.{$operation}", '_title' => "Add {$entity_type->getLabel()}"])->setRequirement('_entity_create_access', $entity_type_id);
         }
         $route->setOption('parameters', $parameters)->setOption('_admin_route', TRUE);
         return $route;
     }
 }
Example #15
0
 /**
  * Gets the delete-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 getDeleteFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('delete-form')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('delete-form'));
         $route->addDefaults(['_entity_form' => "{$entity_type_id}.delete", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::deleteTitle'])->setRequirement('_entity_access', "{$entity_type_id}.delete")->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
         // Entity types with serial IDs can specify this in their route
         // requirements, improving the matching process.
         if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
             $route->setRequirement($entity_type_id, '\\d+');
         }
         return $route;
     }
 }
 /**
  * Gets the delete-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 getDeleteFormRoute(EntityTypeInterface $entity_type)
 {
     if ($entity_type->hasLinkTemplate('delete-form')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('delete-form'));
         $route->addDefaults(['_entity_form' => "{$entity_type_id}.delete", '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::deleteTitle'])->setRequirement('_entity_access', "{$entity_type_id}.delete")->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]);
         return $route;
     }
 }
 /**
  * Gets the collection route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getCollectionRoute(EntityTypeInterface $entity_type)
 {
     // If the entity type does not provide an admin permission, there is no way
     // to control access, so we cannot provide a route in a sensible way.
     if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass() && ($admin_permission = $entity_type->getAdminPermission())) {
         $route = new Route($entity_type->getLinkTemplate('collection'));
         $route->addDefaults(['_entity_list' => $entity_type->id(), '_title' => '@label entities', '_title_arguments' => ['@label' => $entity_type->getLabel()]])->setRequirement('_permission', $admin_permission);
         return $route;
     }
 }
 /**
  * Gets the entity revision version history route.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type.
  *
  * @return \Symfony\Component\Routing\Route|null
  *   The generated route, if available.
  */
 protected function getRevisionHistoryRoute($entity_type)
 {
     if ($entity_type->hasLinkTemplate('version-history')) {
         $entity_type_id = $entity_type->id();
         $route = new Route($entity_type->getLinkTemplate('version-history'));
         $route->addDefaults(['_controller' => '\\Drupal\\entity\\Controller\\RevisionOverviewController::revisionOverviewController', '_title' => 'Revisions']);
         $route->setRequirement('_entity_access_revision', "{$entity_type_id}.list");
         $route->setOption('entity_type_id', $entity_type->id());
         $route->setOption('parameters', [$entity_type->id() => ['type' => 'entity:' . $entity_type->id()]]);
         return $route;
     }
 }