Add a routeExists method to RouteProvider

Created on 30 January 2019, almost 6 years ago
Updated 31 August 2023, over 1 year ago

Problem/Motivation

Drupal\Core\Routing\RouteProvider lacks a routeExists method. There is a close method, getRouteByName, but it throws an exception.

Right now, the standard way of checking of a route exists, based on this answer on drupal.stackexchange.com, is this:

$exists = count($route_provider->getRoutesByNames(['abc.xyz'])) === 1;

https://drupal.stackexchange.com/a/222652/45409

It would be nice if RouteProvider had a public method such as this, or if that's not the best place, some other built in service.

Proposed resolution

It would be useful to have a method added to RouteProvider that doesn't throw an exception, called ::routeExists perhaps.

Remaining tasks

- review

Draft Record Change:
https://www.drupal.org/node/3206861

Feature request
Status

Needs work

Version

11.0 🔥

Component
Routing 

Last updated 3 days ago

Created by

🇺🇸United States oknate Greater New York City Area

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024