You are here

public function PhotosRearrangeController::contentOverview in Album Photos 8.5

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

Returns photos to be rearranged.

Return value

array An array of markup for the page content.

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

File

src/Controller/PhotosRearrangeController.php, line 152

Class

PhotosRearrangeController
Re-arrange view controller.

Namespace

Drupal\photos\Controller

Code

public function contentOverview() {
  $config = $this
    ->config('photos.settings');

  // Get node object.
  $node = $this->routeMatch
    ->getParameter('node');
  $nid = $node
    ->id();
  $output = '';
  $build = [];
  $update_button = '';
  if (isset($node->album['imageorder']) && $node->album['imageorder'] != 'weight|asc') {
    $update_button = ' ' . $this
      ->t('Update album image display order to "Weight - smallest first".');
  }

  // Load library photos.dragndrop.
  $build['#attached']['library'][] = 'photos/photos.dragndrop';

  // Set custom drupalSettings for use in JavaScript file.
  $build['#attached']['drupalSettings']['photos']['album_id'] = $nid;

  // Set custom drupalSettings for use in JavaScript file.
  $build['#attached']['drupalSettings']['photos']['sort'] = 'images';
  $photos_album = new PhotosAlbum($nid);
  $get_limit = $this->requestStack
    ->getCurrentRequest()->query
    ->get('limit');
  $limit = $get_limit ? Html::escape($get_limit) : 50;
  $images = $photos_album
    ->getImages($limit);
  $count = count($images);
  $link_100 = Link::fromTextAndUrl(100, Url::fromUri('base:node/' . $nid . '/photos-rearrange', [
    'query' => [
      'limit' => 100,
    ],
  ]))
    ->toString();
  $link_500 = Link::fromTextAndUrl(500, Url::fromUri('base:node/' . $nid . '/photos-rearrange', [
    'query' => [
      'limit' => 500,
    ],
  ]))
    ->toString();
  $output .= $this
    ->t('Limit: @link_100 - @link_500', [
    '@link_100' => $link_100,
    '@link_500' => $link_500,
  ]);
  $default_message = $this
    ->t('%img_count images to rearrange.', [
    '%img_count' => $count,
  ]);
  $output .= '<div id="photos-sort-message">' . $default_message . $update_button . ' ' . '<span id="photos-sort-updates"></span></div>';
  $output .= '<ul id="photos-sortable" class="photos-sortable">';
  foreach ($images as $image) {
    $output .= '<li id="photos_' . $image['photos_image']
      ->id() . '" class="photos-sort-grid ui-state-default">';
    $viewBuilder = $this->entityTypeManager
      ->getViewBuilder('photos_image');
    $viewMode = $config
      ->get('view_mode_rearrange_image_page') ?: 'sort';
    $renderImage = $viewBuilder
      ->view($image['photos_image'], $viewMode);
    try {
      $output .= $this->renderer
        ->render($renderImage);
    } catch (\Exception $e) {
      watchdog_exception('photos', $e);
    }
    $output .= '</li>';
  }
  $output .= '</ul>';
  $build['#markup'] = $output;
  $build['#cache'] = [
    'tags' => [
      'node:' . $nid,
      'photos:album:' . $nid,
    ],
  ];
  return $build;
}