protected function MenuLinkStorageController::findRouteName

Returns the route_name matching a URL.

Parameters

string $link_path: The link path to find a route name for.

Return value

string The route name.

1 call to MenuLinkStorageController::findRouteName()
MenuLinkStorageController::preSave in drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
Overrides DatabaseStorageController::preSave().

File

drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php, line 283
Contains \Drupal\menu_link\MenuLinkStorageController.

Class

MenuLinkStorageController
Controller class for menu links.

Namespace

Drupal\menu_link

Code

protected function findRouteName($link_path) {

  // Look up the route_name used for the given path.
  $request = Request::create('/' . $link_path);
  $request->attributes
    ->set('system_path', $link_path);
  try {

    // Use router.dynamic instead of router, because router will call the
    // legacy router which will call hook_menu() and you will get back to
    // this method.
    $result = \Drupal::service('router.dynamic')
      ->matchRequest($request);
    return isset($result['_route']) ? $result['_route'] : '';
  } catch (\Exception $e) {
    return '';
  }
}