You are here

class Routes in JSON:API Menu Items 1.0.x

Same name and namespace in other branches
  1. 1.2.x src/Routing/Routes.php \Drupal\jsonapi_menu_items\Routing\Routes
  2. 1.1.x src/Routing/Routes.php \Drupal\jsonapi_menu_items\Routing\Routes

Defines dynamic routes.

Each Menu will result in a jsonapi resource at: /{jsonapi_namespace}/menu_items/{menu_id}

Hierarchy

Expanded class hierarchy of Routes

File

src/Routing/Routes.php, line 17

Namespace

Drupal\jsonapi_menu_items\Routing
View source
class Routes implements ContainerInjectionInterface {
  const RESOURCE_NAME = MenuItemsResource::class;
  const JSONAPI_RESOURCE_KEY = '_jsonapi_resource';

  /**
   * {@inheritdoc}
   */
  public function __construct() {
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static();
  }

  /**
   * {@inheritdoc}
   */
  public function routes() {
    $routes = new RouteCollection();
    $route = new Route('/%jsonapi%/menu_items/{menu}');
    $route
      ->addDefaults([
      static::JSONAPI_RESOURCE_KEY => static::RESOURCE_NAME,
    ]);
    $route
      ->setOption('parameters', [
      'menu' => [
        'type' => 'entity:menu',
      ],
    ]);
    $routes
      ->add('jsonapi_menu_items.menu', $route);
    $routes
      ->addRequirements([
      '_access' => 'TRUE',
    ]);
    return $routes;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Routes::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
Routes::JSONAPI_RESOURCE_KEY constant
Routes::RESOURCE_NAME constant
Routes::routes public function
Routes::__construct public function