You are here

public function PhotosEditController::setAlbumCover in Album Photos 8.4

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

Set album cover.

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

File

src/Controller/PhotosEditController.php, line 320

Class

PhotosEditController
Edit images and image details.

Namespace

Drupal\photos\Controller

Code

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