Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Code snippet that can be used to check if user has permission to special node in Drupal 8.

Example check if current user has permission to update the node:

 $node = \Drupal\node\Entity\Node::load(NID);
  $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
  $check = $node->access('update', $user);

Example check if current user has permission to view the node:

$node = \Drupal\node\Entity\Node::load(NID);
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$check = $node->access('view', $user);

Example check if current user has permission to create the node:

$node = \Drupal\node\Entity\Node::load(NID);
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$check = $node->access('create', $user);

 

Example check if current user has permission to delete the node:

$node = \Drupal\node\Entity\Node::load(NID);
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$check = $node->access('delete', $user);
Tags :

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon