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);

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

I am a senior web developer, I have experience in planning and developing large scale dynamic web applications especially in Drupal, Laravel.

Web Posts

Search

Page Facebook