Skip to main content
added 597 characters in body
Source Link
Alex
  • 2.6k
  • 5
  • 40
  • 63

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

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?

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

edited tags
Link
Alex
  • 2.6k
  • 5
  • 40
  • 63
edited tags
Source Link
avpaderno
  • 98.1k
  • 15
  • 165
  • 284

How todo I check if a user may access a given route?

I am trying to render a link from an Urla Url object and beforehand check whetherverify the user actually has access to that urlURL, like awhen viewing a node.

For some reason, this returns always false:returns FALSE, although the node is accessible when $language is the set language.

$_url = Url::fromRoute('<current>', [], ['language' => $language]);   if ($_url->access()) {  // alwaysThe false code inside here is never executed. } 

Although the node for the looked up language is accessible.

How to check ifdo I verify a user may access the given path, without actually loading the entity behind that path?

How to check if user may access given route?

I am trying to render a link from an Url object and beforehand check whether the user actually has access to that url, like a viewing a node.

For some reason, this returns always false:

$_url = Url::fromRoute('<current>', [], ['language' => $language]);   if ($_url->access()) { // always false  } 

Although the node for the looked up language is accessible.

How to check if a user may access the given path without actually loading the entity behind that?

How do I check if a user may access a given route?

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?

edited tags
Link
avpaderno
  • 98.1k
  • 15
  • 165
  • 284
Loading
Source Link
Alex
  • 2.6k
  • 5
  • 40
  • 63
Loading