- Issue created by @wilco
- 🇨🇦Canada wilco
The following ticket relates to this: https://www.drupal.org/project/type_tray/issues/3244710 📌 Do not hard code /admin/content Fixed
When working with Drupal 10.4, I noticed the following error:
InvalidArgumentException: The user-entered string 'https://test.ddev.site/en/admin/content' must begin with a '/', '?', or '#'. in Drupal\Core\Url::fromUserInput() (line 216 of core/lib/Drupal/Core/Url.php).
Drupal\type_tray\Controller\TypeTrayController->addPage(Object) (Line: 23)
Drupal\gin_type_tray\Controller\GinTypeTrayController->addPage(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
Spool up a site in DDEV using Drupal's WxT Profile, once its running, visit the Add Content and try to add a Basic Page.
Looking at the offending code I found this:
// @codingStandardsIgnoreLine
$all_nodes_label = $this->t($settings['existing_nodes_link_text']);
// Remove scripts/style from the label.
$all_nodes_label = Xss::filterAdmin($all_nodes_label);
$admin_content_url = Url::fromRoute('system.admin_content')->toString();
$all_nodes_url = Url::fromUserInput($admin_content_url, ['query' => ['type' => $type->id()]]);
$build['#items'][$category][$type->id()]['#nodes_by_type_link'] = Link::fromTextAndUrl($all_nodes_label, $all_nodes_url);
There are a few things I believe to be causing the problem here:
Url
and its method fromUserInput
is expecting a path and not a fully qualified domain name. Hence the error.$all_nodes_label
can have HTML in it which leads to html converted characters.I propose the following patch to resolve some of these issues and better contextualize the mechanism:
$admin_content_url = Url::fromRoute('system.admin_content', ['type' => $type->id()]);
$build['#items'][$category][$type->id()]['#nodes_by_type_link'] = [
'#type' => 'link',
'#title' => [
'#markup' => $all_nodes_label,
],
'#url' => $admin_content_url,
'#options' => ['html' => TRUE],
];
Here we pass the type for the admin_content_url
straight into the fromRoute
method, alleviating the need to use a second method and we build the item as a link markup passing the option "html" as true
. This allows the link to render the HTML in the label and improving the extensibility of the code.
Active
1.3
Code
The following ticket relates to this: https://www.drupal.org/project/type_tray/issues/3244710 📌 Do not hard code /admin/content Fixed