public function PhotosRearrangeController::albumRearrange in Album Photos 8.4
Same name and namespace in other branches
- 8.5 src/Controller/PhotosRearrangeController.php \Drupal\photos\Controller\PhotosRearrangeController::albumRearrange()
- 6.0.x src/Controller/PhotosRearrangeController.php \Drupal\photos\Controller\PhotosRearrangeController::albumRearrange()
Rearrange user albums.
1 string reference to 'PhotosRearrangeController::albumRearrange'
File
- src/
Controller/ PhotosRearrangeController.php, line 201
Class
- PhotosRearrangeController
- Re-arrange view controller.
Namespace
Drupal\photos\ControllerCode
public function albumRearrange() {
$config = $this
->config('photos.settings');
$output = '';
$build = [];
$account = $this->routeMatch
->getParameter('user');
if ($account && !is_object($account)) {
$account = $this->entityTypeManager
->getStorage('user')
->load($account);
}
$uid = $account
->id();
// Load library photos.dragndrop.
$build['#attached']['library'][] = 'photos/photos.dragndrop';
// Set custom drupalSettings for use in JavaScript file.
$build['#attached']['drupalSettings']['photos']['uid'] = $uid;
$build['#attached']['drupalSettings']['photos']['sort'] = 'albums';
$albums = $this
->getAlbums($uid);
$count = count($albums);
$limit_uri = Url::fromUri('base:photos/user/' . $uid . '/album-rearrange', [
'query' => [
'limit' => 100,
],
]);
$output .= $this
->t('Limit: @link', [
'@link' => Link::fromTextAndUrl(100, $limit_uri)
->toString(),
]);
$limit_uri = Url::fromUri('base:photos/user/' . $uid . '/album-rearrange', [
'query' => [
'limit' => 500,
],
]);
$output .= ' - ' . Link::fromTextAndUrl(500, $limit_uri)
->toString();
$default_message = $this
->t('%album_count albums to rearrange.', [
'%album_count' => $count,
]);
$output .= '<div id="photos-sort-message">' . $default_message . ' ' . '<span id="photos-sort-updates"></span></div>';
$output .= '<ul id="photos-sortable" class="photos-sortable">';
foreach ($albums as $album) {
$title = $album['title'];
$cover = $this->entityTypeManager
->getStorage('file')
->load($album['fid']);
// @todo set photos_sort_style variable for custom image style settings.
$image_sizes = $config
->get('photos_size');
$style_name = key($image_sizes);
$output .= '<li id="photos_' . $album['nid'] . '" data-id="' . $album['nid'] . '" class="photos-sort-grid">';
$render_image = [
'#theme' => 'image_style',
'#style_name' => $style_name,
'#uri' => $cover
->getFileUri(),
'#alt' => $title,
'#title' => $title,
];
$output .= $this->renderer
->render($render_image);
$output .= '</li>';
}
$output .= '</ul>';
$build['#markup'] = $output;
$build['#cache'] = [
'tags' => [
'user:' . $uid,
],
];
return $build;
}