You are here

class ShipmentRouteProvider in Commerce Shipping 8.2

Provides routes for the Shipment entity.

Hierarchy

Expanded class hierarchy of ShipmentRouteProvider

File

src/ShipmentRouteProvider.php, line 13

Namespace

Drupal\commerce_shipping
View source
class ShipmentRouteProvider extends AdminHtmlRouteProvider {

  /**
   * {@inheritdoc}
   */
  public function getRoutes(EntityTypeInterface $entity_type) {
    $collection = parent::getRoutes($entity_type);
    if ($resend_confirmation_form_route = $this
      ->getResendConfirmationFormRoute($entity_type)) {
      $collection
        ->add("entity.commerce_shipment.resend_confirmation_form", $resend_confirmation_form_route);
    }
    return $collection;
  }

  /**
   * Gets the resend-confirmation-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 getResendConfirmationFormRoute(EntityTypeInterface $entity_type) {
    $route = new Route($entity_type
      ->getLinkTemplate('resend-confirmation-form'));
    $route
      ->addDefaults([
      '_entity_form' => 'commerce_shipment.resend-confirmation',
      '_title_callback' => '\\Drupal\\Core\\Entity\\Controller\\EntityController::title',
    ])
      ->setRequirement('_entity_access', 'commerce_order.resend_receipt')
      ->setRequirement('commerce_order', '\\d+')
      ->setRequirement('commerce_shipment', '\\d+')
      ->setOption('parameters', [
      'commerce_order' => [
        'type' => 'entity:commerce_order',
      ],
      'commerce_shipment' => [
        'type' => 'entity:commerce_shipment',
      ],
    ])
      ->setOption('_admin_route', TRUE);
    return $route;
  }

  /**
   * {@inheritdoc}
   */
  protected function getAddFormRoute(EntityTypeInterface $entity_type) {
    $route = parent::getAddFormRoute($entity_type);
    if ($route) {
      $route
        ->setOption('parameters', [
        'commerce_order' => [
          'type' => 'entity:commerce_order',
        ],
        'commerce_shipment_type' => [
          'type' => 'entity:commerce_shipment_type',
        ],
      ]);
    }
    return $route;
  }

  /**
   * {@inheritdoc}
   */
  protected function getAddPageRoute(EntityTypeInterface $entity_type) {
    $route = parent::getAddPageRoute($entity_type);
    if ($route) {
      $route
        ->setDefault('_controller', ShipmentController::class . '::addShipmentPage');
      $route
        ->setOption('parameters', [
        'commerce_order' => [
          'type' => 'entity:commerce_order',
        ],
      ]);
    }
    return $route;
  }

  /**
   * {@inheritdoc}
   */
  protected function getCollectionRoute(EntityTypeInterface $entity_type) {
    $route = parent::getCollectionRoute($entity_type);
    if ($route) {
      $route
        ->setOption('parameters', [
        'commerce_order' => [
          'type' => 'entity:commerce_order',
        ],
      ]);
      $route
        ->setRequirement('_shipment_collection_access', 'TRUE');
    }
    return $route;
  }

}

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::getCanonicalRoute protected function Gets the canonical route. 3
DefaultHtmlRouteProvider::getDeleteFormRoute protected function Gets the delete-form route. 1
DefaultHtmlRouteProvider::getDeleteMultipleFormRoute protected function Returns the delete multiple form route. 1
DefaultHtmlRouteProvider::getDuplicateFormRoute protected function Gets the duplicate-form route.
DefaultHtmlRouteProvider::getEditFormRoute protected function Gets the edit-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
ShipmentRouteProvider::getAddFormRoute protected function Gets the add-form route. Overrides DefaultHtmlRouteProvider::getAddFormRoute
ShipmentRouteProvider::getAddPageRoute protected function Gets the add page route. Overrides DefaultHtmlRouteProvider::getAddPageRoute
ShipmentRouteProvider::getCollectionRoute protected function Gets the collection route. Overrides DefaultHtmlRouteProvider::getCollectionRoute
ShipmentRouteProvider::getResendConfirmationFormRoute protected function Gets the resend-confirmation-form route.
ShipmentRouteProvider::getRoutes public function Provides routes for entities. Overrides AdminHtmlRouteProvider::getRoutes