You are here

public function ImagePopup::render in Simple Image Popup 8

Same name and namespace in other branches
  1. 2.x src/Controller/ImagePopup.php \Drupal\image_popup\Controller\ImagePopup::render()

Render.

Return value

string Return Hello string.

1 string reference to 'ImagePopup::render'
image_popup.routing.yml in ./image_popup.routing.yml
image_popup.routing.yml

File

src/Controller/ImagePopup.php, line 26
Contains \Drupal\image_popup\Controller\ImagePopup.

Class

ImagePopup
Class ImagePopup.

Namespace

Drupal\image_popup\Controller

Code

public function render($fid, $image_style = NULL) {
  $file = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->load($fid);
  if (!empty($image_style)) {
    $image_style = ImageStyle::load($image_style);
  }
  $image_uri = $file
    ->getFileUri();
  if (!empty($image_style)) {
    $absolute_path = ImageStyle::load($image_style
      ->getName())
      ->buildUrl($image_uri);
  }
  else {

    // Get absolute path for original image.
    $absolute_path = Url::fromUri(file_create_url($image_uri))
      ->getUri();
  }
  $img = "<img src='" . $absolute_path . "'></img>";

  //return [

  //    '#type' => 'markup',
  //    '#markup' => $img,

  //];
  return array(
    '#theme' => 'image_popup_details',
    '#url_popup' => $absolute_path,
  );
}