You are here

function photos_node_load in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 photos.module \photos_node_load()
  2. 7.3 photos.module \photos_node_load()
  3. 6.0.x photos.module \photos_node_load()

Implements hook_ENTITY_TYPE_load().

File

./photos.module, line 707
Implementation of photos.module.

Code

function photos_node_load($nodes) {
  $info = [];
  foreach ($nodes as $nid => $node) {
    if ($node
      ->getType() == 'photos') {
      $db = \Drupal::database();
      $query = $db
        ->select('photos_album')
        ->fields('photos_album')
        ->condition('pid', $node
        ->id());
      $result = $query
        ->execute();
      foreach ($result as $a) {
        if ($a->pid) {
          $info['album'] = [];

          // Check if album data is corrupt to prevent unserialize notice.
          // @todo cleanup remove?
          if ($a->data != 'N;') {
            $info['album'] = unserialize($a->data);
          }
          $info['album']['pid'] = $a->pid;
          $info['album']['count'] = $a->count;
          $photos_album = new PhotosAlbum($a->pid);
          $info['album']['cover'] = $photos_album
            ->getCover($a->fid, $node
            ->getTitle());
          $nodes[$nid]->album = $info['album'];
        }
      }
    }
  }
}