You are here

public function PhotosRearrangeController::editSortAlbumsSave in Album Photos 8.4

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

Save new album weights.

1 call to PhotosRearrangeController::editSortAlbumsSave()
PhotosRearrangeController::ajaxRearrange in src/Controller/PhotosRearrangeController.php
Ajax callback to save new image order.

File

src/Controller/PhotosRearrangeController.php, line 369

Class

PhotosRearrangeController
Re-arrange view controller.

Namespace

Drupal\photos\Controller

Code

public function editSortAlbumsSave($order = [], $uid = 0) {
  if ($uid) {
    $user = $this
      ->currentUser();
    $access = FALSE;

    // @todo add support for admin role?
    if ($user
      ->id() == $uid || $user
      ->id() == 1) {
      $weight = 0;

      // Update weight for all albums in array.
      foreach ($order as $album_id) {
        $pid = str_replace('photos_', '', $album_id);
        $node = $this->entityTypeManager
          ->getStorage('node')
          ->load($pid);

        // Check for node_accss.
        $access = _photos_access('editAlbum', $node);
        if ($access) {
          $this->connection
            ->update('photos_album')
            ->fields([
            'wid' => $weight,
          ])
            ->condition('pid', $pid)
            ->execute();
          $weight++;
        }
      }
      if ($weight > 0) {
        $message = $this
          ->t('Album order saved!');
        return $message;
      }
    }
  }
}