You are here

public function PhotosRearrangeController::contentOverview in Album Photos 8.4

Same name and namespace in other branches
  1. 8.5 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 137

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();

  // Check album type.
  $type = 'album';
  $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']['pid'] = $nid;
  $images = [];
  if ($type == 'album') {

    // 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) {
    $title = $image->title;

    // @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_' . $image->fid . '" data-id="' . $image->fid . '" class="photos-sort-grid">';
    $render_image = [
      '#theme' => 'image_style',
      '#style_name' => $style_name,
      '#uri' => $image->uri,
      '#alt' => $title,
      '#title' => $title,
    ];
    $output .= $this->renderer
      ->render($render_image);
    $output .= '</li>';
  }
  $output .= '</ul>';
  $build['#markup'] = $output;
  $build['#cache'] = [
    'tags' => [
      'node:' . $nid,
      'photos:album:' . $nid,
    ],
  ];
  return $build;
}