You are here

function photos_access_node_load in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos_access/photos_access.module \photos_access_node_load()
  2. 7.3 photos_access/photos_access.module \photos_access_node_load()
  3. 6.0.x photos_access/photos_access.module \photos_access_node_load()

Implements hook_node_load().

File

photos_access/photos_access.module, line 571
Implementation of photos_access.module.

Code

function photos_access_node_load($nodes) {
  foreach ($nodes as $nid => $node) {
    $db = \Drupal::database();
    $result = $db
      ->query('SELECT * FROM {photos_access_album} WHERE nid = :nid', [
      ':nid' => $nid,
    ])
      ->fetchObject();
    $info = [];

    // @todo change privacy to photos_access to avoid potential conflict.
    if ($result) {

      // Node privacy settings.
      $info['privacy'] = [];

      // @todo replace vid and eid with access_id.
      $info['privacy']['access_id'] = $result->id;
      $info['privacy']['vid'] = $result->id;
      $info['privacy']['eid'] = $result->id;
      $info['privacy']['viewid'] = $result->viewid;
      if ($result->viewid == 3) {
        $info['privacy']['pass'] = $result->pass;
      }

      // Users who can collaborate.
      $info['privacy']['updateuser'] = _photos_access_userlist($result->id, TRUE);

      // Users who can view.
      $info['privacy']['viewuser'] = _photos_access_userlist($result->id, FALSE);
      $nodes[$nid]->privacy = $info['privacy'];
    }
  }
}