You are here

public function PhotosAlbum::setCover in Album Photos 8.4

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

Set album cover.

File

src/PhotosAlbum.php, line 268

Class

PhotosAlbum
Create an album object.

Namespace

Drupal\photos

Code

public function setCover($fid = 0) {
  $pid = $this->pid;

  // Update cover.
  $db = \Drupal::database();
  $db
    ->update('photos_album')
    ->fields([
    'fid' => $fid,
  ])
    ->condition('pid', $pid)
    ->execute();

  // Clear node cache.
  Cache::invalidateTags([
    'node:' . $pid,
    'photos:album:' . $pid,
  ]);
  \Drupal::messenger()
    ->addMessage(t('Cover successfully set.'));
}