You are here

public function SocialAlbumController::viewImage in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.0.x modules/social_features/social_album/src/Controller/SocialAlbumController.php \Drupal\social_album\Controller\SocialAlbumController::viewImage()
  2. 10.1.x modules/social_features/social_album/src/Controller/SocialAlbumController.php \Drupal\social_album\Controller\SocialAlbumController::viewImage()
  3. 10.2.x modules/social_features/social_album/src/Controller/SocialAlbumController.php \Drupal\social_album\Controller\SocialAlbumController::viewImage()

Provides a page with images slider.

Parameters

\Drupal\node\NodeInterface $node: The node object.

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

int $fid: The file entity ID.

Return value

array The renderable array.

1 string reference to 'SocialAlbumController::viewImage'
social_album.routing.yml in modules/social_features/social_album/social_album.routing.yml
modules/social_features/social_album/social_album.routing.yml

File

modules/social_features/social_album/src/Controller/SocialAlbumController.php, line 105

Class

SocialAlbumController
Returns responses for Album routes.

Namespace

Drupal\social_album\Controller

Code

public function viewImage(NodeInterface $node, PostInterface $post, $fid) {
  $query = $this->database
    ->select('post__field_post_image', 'i')
    ->fields('i', [
    'field_post_image_target_id',
  ]);
  $query
    ->innerJoin('post__field_album', 'a', 'a.entity_id = i.entity_id');
  $query
    ->condition('a.field_album_target_id', $node
    ->id());
  $query
    ->innerJoin('post_field_data', 'p', 'p.id = a.entity_id');
  $query
    ->fields('p', [
    'id',
  ]);
  $query
    ->orderBy('p.created');
  $query
    ->orderBy('i.delta');
  $items = [
    FALSE => [],
    TRUE => [],
  ];
  $found = FALSE;

  /** @var \Drupal\file\FileStorageInterface $storage */
  $storage = $this
    ->entityTypeManager()
    ->getStorage('file');
  foreach ($query
    ->execute()
    ->fetchAllKeyed() as $file_id => $post_id) {
    if (!$found && $file_id == $fid) {
      $found = TRUE;
    }

    /** @var \Drupal\file\FileInterface $file */
    $file = $storage
      ->load($file_id);
    $items[$found][] = [
      'url' => Url::fromUri(file_create_url($file
        ->getFileUri()))
        ->setAbsolute()
        ->toString(),
      'pid' => $post_id,
    ];
  }
  return [
    '#theme' => 'social_album_post',
    '#items' => array_merge($items[TRUE], $items[FALSE]),
    '#album' => $node
      ->label(),
  ];
}