You are here

public function ImagePopupController::render in Open Social 10.0.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_post/modules/social_post_album/src/Controller/ImagePopupController.php \Drupal\social_post_album\Controller\ImagePopupController::render()
  2. 10.1.x modules/social_features/social_post/modules/social_post_album/src/Controller/ImagePopupController.php \Drupal\social_post_album\Controller\ImagePopupController::render()
  3. 10.2.x modules/social_features/social_post/modules/social_post_album/src/Controller/ImagePopupController.php \Drupal\social_post_album\Controller\ImagePopupController::render()

Render images and post in pop-up.

Parameters

\Drupal\social_post\Entity\PostInterface $post: The post entity.

string $first_fid: The first file ID.

Return value

array Return render array.

See also

https://git.drupalcode.org/project/image_popup/-/blob/2.x/src/Controller...

1 string reference to 'ImagePopupController::render'
social_post_album.routing.yml in modules/social_features/social_post/modules/social_post_album/social_post_album.routing.yml
modules/social_features/social_post/modules/social_post_album/social_post_album.routing.yml

File

modules/social_features/social_post/modules/social_post_album/src/Controller/ImagePopupController.php, line 29

Class

ImagePopupController
Returns responses for Post Album routes.

Namespace

Drupal\social_post_album\Controller

Code

public function render(PostInterface $post, $first_fid) {
  $items = [
    FALSE => [],
    TRUE => [],
  ];
  $found = FALSE;

  /** @var \Drupal\file\FileStorageInterface $storage */
  $storage = $this
    ->entityTypeManager()
    ->getStorage('file');

  // Show images in the correct order.
  foreach ($post->field_post_image
    ->getValue() as $file) {
    if (!$found && $file['target_id'] == $first_fid) {
      $found = TRUE;
    }

    /** @var \Drupal\file\FileInterface $file */
    $file = $storage
      ->load($file['target_id']);
    $items[$found][] = Url::fromUri(file_create_url($file
      ->getFileUri()))
      ->setAbsolute()
      ->toString();
  }
  return [
    '#theme' => 'album_post_popup',
    '#urls' => array_merge($items[TRUE], $items[FALSE]),
    '#pid' => $post
      ->id(),
  ];
}