You are here

class GroupContentRouteProvider in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Routing/GroupContentRouteProvider.php \Drupal\group\Entity\Routing\GroupContentRouteProvider

Provides routes for group content.

Hierarchy

Expanded class hierarchy of GroupContentRouteProvider

File

src/Entity/Routing/GroupContentRouteProvider.php, line 15

Namespace

Drupal\group\Entity\Routing
View source
class GroupContentRouteProvider extends DefaultHtmlRouteProvider {

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = parent::getRoutes($entity_type);
    if ($create_page_route = $this
      ->getCreatePageRoute($entity_type)) {
      $collection
        ->add("entity.group_content.create_page", $create_page_route);
    }
    if ($create_form_route = $this
      ->getCreateFormRoute($entity_type)) {
      $collection
        ->add("entity.group_content.create_form", $create_form_route);
    }
    return $collection;
  }

  /**
   * {@inheritdoc}
   */
  protected function getAddPageRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('add-page') && $entity_type
      ->getKey('bundle')) {
      $route = new Route($entity_type
        ->getLinkTemplate('add-page'));
      $route
        ->setDefault('_controller', '\\Drupal\\group\\Entity\\Controller\\GroupContentController::addPage')
        ->setDefault('_title', 'Add existing content')
        ->setRequirement('_group_content_create_any_access', 'TRUE')
        ->setOption('_group_operation_route', TRUE);
      return $route;
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function getAddFormRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('add-form')) {
      $route = new Route($entity_type
        ->getLinkTemplate('add-form'));
      $route
        ->setDefaults([
        '_controller' => '\\Drupal\\group\\Entity\\Controller\\GroupContentController::addForm',
        // @todo Let forms set title?
        '_title_callback' => '\\Drupal\\group\\Entity\\Controller\\GroupContentController::addFormTitle',
      ])
        ->setRequirement('_group_content_create_access', 'TRUE')
        ->setOption('_group_operation_route', TRUE);
      return $route;
    }
  }

  /**
   * Gets the create-page route.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type.
   *
   * @return \Symfony\Component\Routing\Route|null
   *   The generated route, if available.
   */
  protected function getCreatePageRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('create-page') && $entity_type
      ->getKey('bundle')) {
      $route = new Route($entity_type
        ->getLinkTemplate('create-page'));
      $route
        ->setDefault('_controller', '\\Drupal\\group\\Entity\\Controller\\GroupContentController::addPage')
        ->setDefault('_title', 'Add new content')
        ->setDefault('create_mode', TRUE)
        ->setRequirement('_group_content_create_any_entity_access', 'TRUE')
        ->setOption('_group_operation_route', TRUE);
      return $route;
    }
  }

  /**
   * Gets the create-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 getCreateFormRoute(EntityTypeInterface $entity_type) {
    if ($entity_type
      ->hasLinkTemplate('create-form')) {
      $route = new Route($entity_type
        ->getLinkTemplate('create-form'));
      $route
        ->setDefaults([
        '_controller' => '\\Drupal\\group\\Entity\\Controller\\GroupContentController::createForm',
        // @todo Let forms set title?
        '_title_callback' => '\\Drupal\\group\\Entity\\Controller\\GroupContentController::createFormTitle',
      ])
        ->setRequirement('_group_content_create_entity_access', 'TRUE')
        ->setOption('_group_operation_route', TRUE);
      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 ($entity_type
      ->hasLinkTemplate('collection') && $entity_type
      ->hasListBuilderClass()) {
      $route = new Route($entity_type
        ->getLinkTemplate('collection'));
      $route
        ->addDefaults([
        '_entity_list' => 'group_content',
        '_title_callback' => '\\Drupal\\group\\Entity\\Controller\\GroupContentController::collectionTitle',
      ])
        ->setRequirement('_group_permission', "access content overview")
        ->setOption('_group_operation_route', TRUE)
        ->setOption('parameters', [
        'group' => [
          'type' => 'entity:group',
        ],
      ]);
      return $route;
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
    return parent::getCanonicalRoute($entity_type)
      ->setRequirement('_group_owns_content', 'TRUE')
      ->setOption('parameters', [
      'group' => [
        'type' => 'entity:group',
      ],
      'group_content' => [
        'type' => 'entity:group_content',
      ],
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditFormRoute(EntityTypeInterface $entity_type) {
    return parent::getEditFormRoute($entity_type)
      ->setDefault('_title_callback', '\\Drupal\\group\\Entity\\Controller\\GroupContentController::editFormTitle')
      ->setRequirement('_group_owns_content', 'TRUE')
      ->setOption('_group_operation_route', TRUE)
      ->setOption('parameters', [
      'group' => [
        'type' => 'entity:group',
      ],
      'group_content' => [
        'type' => 'entity:group_content',
      ],
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function getDeleteFormRoute(EntityTypeInterface $entity_type) {
    return parent::getDeleteFormRoute($entity_type)
      ->setRequirement('_group_owns_content', 'TRUE')
      ->setOption('_group_operation_route', TRUE)
      ->setOption('parameters', [
      'group' => [
        'type' => 'entity:group',
      ],
      'group_content' => [
        'type' => 'entity:group_content',
      ],
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::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
GroupContentRouteProvider::getAddFormRoute protected function Gets the add-form route. Overrides DefaultHtmlRouteProvider::getAddFormRoute
GroupContentRouteProvider::getAddPageRoute protected function Gets the add page route. Overrides DefaultHtmlRouteProvider::getAddPageRoute
GroupContentRouteProvider::getCanonicalRoute protected function Gets the canonical route. Overrides DefaultHtmlRouteProvider::getCanonicalRoute
GroupContentRouteProvider::getCollectionRoute protected function Gets the collection route. Overrides DefaultHtmlRouteProvider::getCollectionRoute
GroupContentRouteProvider::getCreateFormRoute protected function Gets the create-form route.
GroupContentRouteProvider::getCreatePageRoute protected function Gets the create-page route.
GroupContentRouteProvider::getDeleteFormRoute protected function Gets the delete-form route. Overrides DefaultHtmlRouteProvider::getDeleteFormRoute
GroupContentRouteProvider::getEditFormRoute protected function Gets the edit-form route. Overrides DefaultHtmlRouteProvider::getEditFormRoute
GroupContentRouteProvider::getRoutes public function Provides routes for entities. Overrides DefaultHtmlRouteProvider::getRoutes