You are here

public function PhotosLegacyImageViewController::load in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/Controller/PhotosLegacyImageViewController.php \Drupal\photos\Controller\PhotosLegacyImageViewController::load()

Load image file and album data.

1 call to PhotosLegacyImageViewController::load()
PhotosLegacyImageViewController::view in src/Controller/PhotosLegacyImageViewController.php
Provides a page to render a single entity.

File

src/Controller/PhotosLegacyImageViewController.php, line 192

Class

PhotosLegacyImageViewController
Image view controller.

Namespace

Drupal\photos\Controller

Code

public function load($fid) {

  // Query image data.
  // @todo check access. Is ->addTag('node_access') needed here? If so, rewrite query.
  //   - I think access is already checked before we get here.
  $db = \Drupal::database();

  // @todo join image field if available.
  $image = $db
    ->query('SELECT f.fid, f.uri, f.filemime, f.created, f.filename, n.title as node_title, a.data, u.uid, u.name, p.*
      FROM {file_managed} f
      INNER JOIN {photos_image__field_image} i ON f.fid = i.field_image_target_id
      INNER JOIN {photos_image_field_data} p ON p.revision_id = i.revision_id
      INNER JOIN {node_field_data} n ON p.album_id = n.nid
      INNER JOIN {photos_album} a ON a.album_id = n.nid
      INNER JOIN {users_field_data} u ON f.uid = u.uid
      WHERE f.fid = :fid', [
    ':fid' => $fid,
  ])
    ->fetchObject();

  // Set image height and width.
  if (!isset($image->height) && isset($image->uri)) {

    // The image.factory service will check if our image is valid.
    $image_info = \Drupal::service('image.factory')
      ->get($image->uri);
    if ($image_info
      ->isValid()) {
      $image->width = $image_info
        ->getWidth();
      $image->height = $image_info
        ->getHeight();
    }
    else {
      $image->width = $image->height = NULL;
    }
  }
  return $image;
}