You are here

function photos_preprocess_photos_image_html in Album Photos 8.4

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

Implements hook_preprocess_HOOK().

File

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

Code

function photos_preprocess_photos_image_html(&$variables, $hook) {
  $style_name = $variables['style_name'];
  $image = $variables['image'];
  $filename = isset($image->filename) ? strip_tags($image->filename) : '';
  $title = isset($image->title) ? strip_tags($image->title) : $filename;
  $alt = isset($image->alt) ? strip_tags($image->alt) : $title;
  $image->alt = $alt;
  if ($style_name == 'original') {
    $image_styles = image_style_options(FALSE);
    if (isset($image_styles['original'])) {

      // Original image style override.
      // Render image view.
      // @todo redundant code.
      $image_view_array = [
        '#theme' => 'image_style',
        '#style_name' => $style_name,
        '#uri' => $image->uri,
        '#width' => $image->width,
        '#height' => $image->height,
        '#title' => $alt,
        '#alt' => $alt,
      ];
    }
    else {

      // Original image.
      $image_view_array = [
        '#theme' => 'image',
        '#uri' => $image->uri,
        '#width' => $image->width,
        '#height' => $image->height,
        '#title' => $alt,
        '#alt' => $alt,
      ];
    }
  }
  else {

    // Check scheme and prep image.
    $scheme = \Drupal::service('stream_wrapper_manager')
      ->getScheme($image->uri);
    $uri = $image->uri;

    // If private create temporary derivative.
    if ($scheme == 'private') {
      $photos_image = new PhotosImage($image->fid);
      $url = $photos_image
        ->derivative($uri, $style_name, $scheme);

      // Do not use filename as alt or title with private files.
      if ($alt == $filename) {
        $alt = '';
      }
      if ($title == $filename) {
        $title = '';
      }
    }
    else {

      // Public and all other images.
      $style = ImageStyle::load($style_name);
      $url = $style
        ->buildUrl($uri);
    }

    // Render image view.
    $image_view_array = [
      '#theme' => 'image',
      '#uri' => $url,
      '#title' => $alt,
      '#alt' => $alt,
    ];
  }
  $image->view = $image_view_array;
}