public static function NodeAccess::rebuildNodeAccessOne in Permissions by Term 8.2
Rebuild node access for a single node.
Parameters
int $nid: The node id for which node access records are to be recalculated.
1 call to NodeAccess::rebuildNodeAccessOne()
- NodeAccess::rebuildAccess in src/
Service/ NodeAccess.php
File
- src/
Service/ NodeAccess.php, line 271
Class
- NodeAccess
- Class NodeAccess
Namespace
Drupal\permissions_by_term\ServiceCode
public static function rebuildNodeAccessOne($nid) {
// Delete existing grants for this node only.
\Drupal::database()
->delete('node_access')
->condition('nid', $nid)
->execute();
\Drupal::entityTypeManager()
->getStorage('node')
->resetCache([
$nid,
]);
$node = Node::load($nid);
// To preserve database integrity, only write grants if the node
// loads successfully.
if (!empty($node)) {
$grants = \Drupal::entityTypeManager()
->getAccessControlHandler('node')
->acquireGrants($node);
\Drupal::service('node.grant_storage')
->write($node, $grants);
}
return 'Processed node ' . $nid;
}