I am trying to render a link from a Url
object and verify the user actually has access to that URL, like when viewing a node.
For some reason, this always returns FALSE
, although the node is accessible when $language
is the set language.
$_url = Url::fromRoute('<current>', [], ['language' => $language]);
if ($_url->access()) {
// The code inside here is never executed.
}
How do I verify a user may access the given path, without actually loading the entity behind that path?
edit: current state:
$currentPath = \Drupal::service('path.current')->getPath();
$urlObject = Url::fromUserInput($currentPath);
$routeName = $urlObject->getRouteName();
$linkUrl = Url::fromRoute($routeName, [], ['language' => $dataLangId]);
debug($languageData['languageName']);
debug($linkUrl->toString());
if ($linkUrl->access()) {
debug('access');
}
else {
debug('denied');
}
results in:
Some mandatory parameters are missing ("node") to generate a URL for route "entity.node.canonical