You are here

public function PhotosRearrangeController::albumRearrange in Album Photos 8.5

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

Rearrange user albums.

1 string reference to 'PhotosRearrangeController::albumRearrange'
photos.routing.yml in ./photos.routing.yml
photos.routing.yml

File

src/Controller/PhotosRearrangeController.php, line 207

Class

PhotosRearrangeController
Re-arrange view controller.

Namespace

Drupal\photos\Controller

Code

public function albumRearrange() {
  $config = $this
    ->config('photos.settings');
  $output = '';
  $build = [];
  $account = $this->routeMatch
    ->getParameter('user');
  $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::fromRoute('photos.album.rearrange', [
    'user' => $uid,
  ], [
    'query' => [
      'limit' => 100,
    ],
  ]);
  $output .= $this
    ->t('Limit: @link', [
    '@link' => Link::fromTextAndUrl(100, $limit_uri)
      ->toString(),
  ]);
  $limit_uri = Url::fromRoute('photos.album.rearrange', [
    'user' => $uid,
  ], [
    '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) {
    $output .= '<li id="photos_' . $album['nid'] . '" class="photos-sort-grid ui-state-default">';
    $photosImage = $this->entityTypeManager
      ->getStorage('photos_image')
      ->load($album['cover_id']);
    $viewBuilder = $this->entityTypeManager
      ->getViewBuilder('photos_image');
    $viewMode = $config
      ->get('view_mode_rearrange_album_page') ?: 'sort';
    $renderImage = $viewBuilder
      ->view($photosImage, $viewMode);
    $output .= $this->renderer
      ->render($renderImage);
    $output .= '</li>';
  }
  $output .= '</ul>';
  $build['#markup'] = $output;
  $build['#cache'] = [
    'tags' => [
      'user:' . $uid,
    ],
  ];
  return $build;
}