From e6810f3c30aee060b528d3d465a66076bf4a6e67 Mon Sep 17 00:00:00 2001 From: Chi-teck Date: Sat, 25 Jun 2022 16:11:33 +0500 Subject: [PATCH 1/4] Add url option to the core:route command --- src/Drupal/Commands/core/DrupalCommands.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Drupal/Commands/core/DrupalCommands.php b/src/Drupal/Commands/core/DrupalCommands.php index 286f8c2ce3..5b4388b6fc 100644 --- a/src/Drupal/Commands/core/DrupalCommands.php +++ b/src/Drupal/Commands/core/DrupalCommands.php @@ -149,13 +149,19 @@ public function requirements($options = ['format' => 'table', 'severity' => -1, * @option path An internal path. * @version 10.5 */ - public function route($options = ['name' => self::REQ, 'path' => self::REQ, 'format' => 'yaml']) + public function route($options = ['name' => self::REQ, 'path' => self::REQ, 'url' => self::REQ, 'format' => 'yaml']) { $route = $items = null; $provider = $this->getRouteProvider(); if ($path = $options['path']) { $name = Url::fromUserInput($path)->getRouteName(); $route = $provider->getRouteByName($name); + } elseif ($url = $options['url']) { + $path = \parse_url($url, 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']) { $route = $provider->getRouteByName($name); } From 3d8426fd552e6f3ffd6214bdbe7358066edf6236 Mon Sep 17 00:00:00 2001 From: Chi-teck Date: Sat, 25 Jun 2022 16:12:59 +0500 Subject: [PATCH 2/4] Add usage --- src/Drupal/Commands/core/DrupalCommands.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Drupal/Commands/core/DrupalCommands.php b/src/Drupal/Commands/core/DrupalCommands.php index 5b4388b6fc..79573c82ec 100644 --- a/src/Drupal/Commands/core/DrupalCommands.php +++ b/src/Drupal/Commands/core/DrupalCommands.php @@ -145,6 +145,8 @@ 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 + * View details about the entity.node.canonical route. * @option name A route name. * @option path An internal path. * @version 10.5 From bcae7cefe12d6b81124a1170f4b3818c6af13b35 Mon Sep 17 00:00:00 2001 From: Chi-teck Date: Fri, 1 Jul 2022 12:42:29 +0500 Subject: [PATCH 3/4] Enhance path processing to support URLs --- src/Drupal/Commands/core/DrupalCommands.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Drupal/Commands/core/DrupalCommands.php b/src/Drupal/Commands/core/DrupalCommands.php index 79573c82ec..8221a80813 100644 --- a/src/Drupal/Commands/core/DrupalCommands.php +++ b/src/Drupal/Commands/core/DrupalCommands.php @@ -145,25 +145,24 @@ 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 + * @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, 'url' => self::REQ, 'format' => 'yaml']) + public function route($options = ['name' => self::REQ, 'path' => self::REQ,'format' => 'yaml']) { $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 ($url = $options['url']) { - $path = \parse_url($url, 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']) { $route = $provider->getRouteByName($name); } From 677d58e318853f948d0543aef6cf06dd42c66ca1 Mon Sep 17 00:00:00 2001 From: Chi-teck Date: Fri, 1 Jul 2022 12:44:14 +0500 Subject: [PATCH 4/4] Fix spacing --- src/Drupal/Commands/core/DrupalCommands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal/Commands/core/DrupalCommands.php b/src/Drupal/Commands/core/DrupalCommands.php index 8221a80813..0bf2f14552 100644 --- a/src/Drupal/Commands/core/DrupalCommands.php +++ b/src/Drupal/Commands/core/DrupalCommands.php @@ -151,7 +151,7 @@ public function requirements($options = ['format' => 'table', 'severity' => -1, * @option path An internal path or URL. * @version 10.5 */ - public function route($options = ['name' => self::REQ, 'path' => self::REQ,'format' => 'yaml']) + public function route($options = ['name' => self::REQ, 'path' => self::REQ, 'format' => 'yaml']) { $route = $items = null; $provider = $this->getRouteProvider();