You are here

public function PhotosEditController::setAlbumCover in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/Controller/PhotosEditController.php \Drupal\photos\Controller\PhotosEditController::setAlbumCover()
  2. 8.4 src/Controller/PhotosEditController.php \Drupal\photos\Controller\PhotosEditController::setAlbumCover()

Set album cover.

Parameters

\Drupal\node\NodeInterface $node: The photo album node.

\Drupal\photos\PhotosImageInterface $photos_image: The photos_image entity.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirect to destination or photo album node page.

1 string reference to 'PhotosEditController::setAlbumCover'
photos.routing.yml in ./photos.routing.yml
photos.routing.yml

File

src/Controller/PhotosEditController.php, line 158

Class

PhotosEditController
Edit images and image details.

Namespace

Drupal\photos\Controller

Code

public function setAlbumCover(NodeInterface $node, PhotosImageInterface $photos_image) {
  $nid = $node
    ->id();
  $album_id = $this->connection
    ->query('SELECT album_id FROM {photos_image_field_data} WHERE id = :cover_id', [
    ':cover_id' => $photos_image
      ->id(),
  ])
    ->fetchField();
  if ($album_id == $nid) {
    $album = new PhotosAlbum($album_id);
    $album
      ->setCover($photos_image
      ->id());
    $get_destination = $this->requestStack
      ->getCurrentRequest()->query
      ->get('destination');
    if ($get_destination) {
      $goto = Url::fromUri('base:' . $get_destination)
        ->toString();
    }
    else {
      $goto = $photos_image
        ->getAlbumUrl()
        ->toString();
    }
    return new RedirectResponse($goto);
  }
  else {
    throw new NotFoundHttpException();
  }
}