You are here

function photos_node_view in Album Photos 8.4

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

Implements hook_ENTITY_TYPE_view().

File

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

Code

function photos_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {
  if ($node
    ->getType() == 'photos') {
    $user = \Drupal::currentUser();
    if ($user
      ->hasPermission('view photo')) {
      $display_types = [
        'none',
        'cover',
        'thumbnails',
        'covercolorbox',
      ];
      switch ($view_mode) {
        case 'full':
          $default_display = \Drupal::config('photos.settings')
            ->get('photos_display_page_display');
          $display = isset($node->album['page_display']) ? $node->album['page_display'] : $default_display;
          $photos_album = new PhotosAlbum($node
            ->id());
          $album_view = $photos_album
            ->nodeView($node, $display, $view_mode);
          $build['photos_album-' . $display_types[$display]] = $album_view;
          break;
        case 'teaser':
          $default_display = \Drupal::config('photos.settings')
            ->get('photos_display_teaser_display');
          $display = isset($node->album['teaser_display']) ? $node->album['teaser_display'] : $default_display;
          $photos_album = new PhotosAlbum($node
            ->id());
          $album_view = $photos_album
            ->nodeView($node, $display, $view_mode);
          $build['photos_album-' . $display_types[$display]] = $album_view;
          break;
      }
    }
  }
}