diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkInterface.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkInterface.php index c185dc4..de4700a 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkInterface.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkInterface.php @@ -56,15 +56,15 @@ public function reset(); public static function buildFromRouterItem(array $item); /** - * Returns the route_name matching a URL. + * Returns the route_name and route parameters matching a URL. * * @param string $link_path * The link path to find a route name for. * - * @return string - * The route name. + * @return array + * Returns an array with both the route name and parameters. */ - public static function findRouteName($link_path); + public static function findRouteNameParameters($link_path); /** * Sets the p1 through p9 properties for a menu link entity being saved. diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php index 2adf1b7..ba41d02 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/Plugin/Core/Entity/MenuLink.php @@ -256,6 +256,13 @@ class MenuLink extends Entity implements \ArrayAccess, MenuLinkInterface { public $route_name; /** + * The parameters of the route associated with this menu link, if any. + * + * @var array + */ + public $route_parameters; + + /** * The route object associated with this menu link, if any. * * @var \Symfony\Component\Routing\Route @@ -484,7 +491,13 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { } // Find the route_name. if (!isset($this->route_name)) { - $this->route_name = $this::findRouteName($this->link_path); + if ($result = $this::findRouteNameParameters($this->link_path)) { + list($this->route_name, $this->route_parameters) = $result; + } + else { + $this->route_name = ''; + $this->route_parameters = array(); + } } } @@ -507,7 +520,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ /** * {@inheritdoc} */ - public static function findRouteName($link_path) { + public static function findRouteNameParameters($link_path) { // Look up the route_name used for the given path. $request = Request::create('/' . $link_path); $request->attributes->set('_system_path', $link_path); @@ -516,10 +529,13 @@ public static function findRouteName($link_path) { // 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'] : ''; + $return = array(); + $return[] = isset($result['_route']) ? $result['_route'] : ''; + $return[] = $result['_raw_variables']->all(); + return $return; } catch (\Exception $e) { - return ''; + return array(); } } diff --git a/core/modules/menu_link/menu_link.install b/core/modules/menu_link/menu_link.install index a09be43..976653f 100644 --- a/core/modules/menu_link/menu_link.install +++ b/core/modules/menu_link/menu_link.install @@ -202,6 +202,13 @@ function menu_link_schema() { 'type' => 'varchar', 'length' => 255, ), + 'route_parameters' => array( + 'description' => 'Serialized array of route parameters of this menu link.', + 'type' => 'blob', + 'size' => 'big', + 'not null' => FALSE, + 'serialize' => TRUE, + ), ), 'indexes' => array( 'path_menu' => array(array('link_path', 128), 'menu_name'),