From 36924fa95e46e2e60a8a5e1bdbe64e1f0837818c Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 1 Jul 2022 17:01:02 +0500 Subject: [PATCH] Add url option to the core:route command (#5172) * Add url option to the core:route command * Add usage * Enhance path processing to support URLs * Fix spacing --- src/Drupal/Commands/core/DrupalCommands.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Drupal/Commands/core/DrupalCommands.php b/src/Drupal/Commands/core/DrupalCommands.php index 286f8c2ce3..0bf2f14552 100644 --- a/src/Drupal/Commands/core/DrupalCommands.php +++ b/src/Drupal/Commands/core/DrupalCommands.php @@ -145,8 +145,10 @@ public function requirements($options = ['format' => 'table', 'severity' => -1, * View details about the update.status route. * @usage drush route --path=/user/1 * View details about the entity.user.canonical route. + * @usage drush route --url=https://example.com/node/1 + * View details about the entity.node.canonical route. * @option name A route name. - * @option path An internal path. + * @option path An internal path or URL. * @version 10.5 */ public function route($options = ['name' => self::REQ, 'path' => self::REQ, 'format' => 'yaml']) @@ -154,6 +156,11 @@ public function route($options = ['name' => self::REQ, 'path' => self::REQ, 'for $route = $items = null; $provider = $this->getRouteProvider(); if ($path = $options['path']) { + if (filter_var($path, FILTER_VALIDATE_URL)) { + $path = parse_url($path, PHP_URL_PATH); + // Strip base path. + $path = '/' . substr_replace($path, '', 0, strlen(base_path())); + } $name = Url::fromUserInput($path)->getRouteName(); $route = $provider->getRouteByName($name); } elseif ($name = $options['name']) {