public function PhotosRearrangeController::editSortSave in Album Photos 8.4
Same name and namespace in other branches
- 8.5 src/Controller/PhotosRearrangeController.php \Drupal\photos\Controller\PhotosRearrangeController::editSortSave()
- 6.0.x src/Controller/PhotosRearrangeController.php \Drupal\photos\Controller\PhotosRearrangeController::editSortSave()
Save new order.
1 call to PhotosRearrangeController::editSortSave()
- PhotosRearrangeController::ajaxRearrange in src/
Controller/ PhotosRearrangeController.php - Ajax callback to save new image order.
File
- src/
Controller/ PhotosRearrangeController.php, line 333
Class
- PhotosRearrangeController
- Re-arrange view controller.
Namespace
Drupal\photos\ControllerCode
public function editSortSave($order = [], $nid = 0, $type = 'images') {
if ($nid) {
$access = FALSE;
if ($nid) {
$node = $this->entityTypeManager
->getStorage('node')
->load($nid);
// Check for node_accss.
$access = _photos_access('editAlbum', $node);
}
if ($access) {
$weight = 0;
// Update weight for all images in array / album.
foreach ($order as $image_id) {
$fid = str_replace('photos_', '', $image_id);
if ($type == 'images') {
// Save sort order for images in album.
$this->connection
->update('photos_image')
->fields([
'wid' => $weight,
])
->condition('fid', $fid)
->condition('pid', $nid)
->execute();
}
$weight++;
}
if ($weight > 0) {
$message = $this
->t('Image order saved!');
return $message;
}
}
}
}