You are here

function simple_access_node_save in Simple Access 8.3

Same name and namespace in other branches
  1. 7.2 simple_access.module \simple_access_node_save()

Save node information.

2 calls to simple_access_node_save()
simple_access_node_insert in ./simple_access.module
Implements hook_node_insert().
simple_access_node_update in ./simple_access.module
Implements hook_node_update().

File

./simple_access.module, line 82
Builds simple access definition for content access.

Code

function simple_access_node_save(NodeInterface $node) {
  \Drupal::database()
    ->delete('simple_access_node_group')
    ->condition('nid', $node
    ->id())
    ->execute();
  if (isset($node->simple_access['groups'])) {
    foreach ($node->simple_access['groups'] as $gid => $access) {
      if ($access['view'] || $access['update'] || $access['delete']) {
        \Drupal::database()
          ->insert('simple_access_node_group')
          ->fields([
          'nid' => $node
            ->id(),
          'gid' => $gid,
          'grant_view' => $access['view'],
          'grant_update' => $access['update'],
          'grant_delete' => $access['delete'],
        ])
          ->execute();
      }
    }
  }
  \Drupal::database()
    ->delete('simple_access_node_profile')
    ->condition('nid', $node
    ->id())
    ->execute();
  if (isset($node->simple_access['profiles'])) {
    foreach (array_filter($node->simple_access['profiles']) as $pid) {
      \Drupal::database()
        ->insert('simple_access_node_profile')
        ->fields([
        'nid' => $node
          ->id(),
        'pid' => $pid,
      ])
        ->execute();
    }
  }
}