protected function MenuLinkConfigForm::extractUrl in Config menu link 8
Breaks up a user-entered URL or path into all the relevant parts.
Parameters
string $url: The user-entered URL or path.
Return value
array The extracted parts.
2 calls to MenuLinkConfigForm::extractUrl()
- MenuLinkConfigForm::doValidate in src/
Plugin/ Menu/ Form/ MenuLinkConfigForm.php - Validates the form, both on the menu link edit and content menu link form.
- MenuLinkConfigForm::extractFormValues in src/
Plugin/ Menu/ Form/ MenuLinkConfigForm.php - Extracts a plugin definition from form values.
File
- src/
Plugin/ Menu/ Form/ MenuLinkConfigForm.php, line 363 - Contains \Drupal\menu_link_config\Plugin\Menu\Form\MenuLinkConfigForm.
Class
Namespace
Drupal\menu_link_config\Plugin\Menu\FormCode
protected function extractUrl($url) {
$extracted = UrlHelper::parse($url);
$external = UrlHelper::isExternal($url);
if ($external) {
$extracted['url'] = $extracted['path'];
$extracted['route_name'] = NULL;
$extracted['route_parameters'] = [];
}
else {
$extracted['url'] = '';
// If the path doesn't match a Drupal path, the route should end up empty.
$extracted['route_name'] = NULL;
$extracted['route_parameters'] = [];
try {
// Find the route_name.
$url_obj = \Drupal::pathValidator()
->getUrlIfValid($extracted['path']);
if ($url_obj) {
$extracted['route_name'] = $url_obj
->getRouteName();
$extracted['route_parameters'] = $url_obj
->getRouteParameters();
}
} catch (MatchingRouteNotFoundException $e) {
// The path doesn't match a Drupal path.
} catch (ParamNotConvertedException $e) {
// A path like node/99 matched a route, but the route parameter was
// invalid (e.g. node with ID 99 does not exist).
}
if ($url == 'route:<nolink>') {
$extracted['route_name'] = '<nolink>';
}
}
return $extracted;
}