public static function PhotosAlbum::orderLinks in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::orderLinks()
- 8.4 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::orderLinks()
Limit and sort by links.
2 calls to PhotosAlbum::orderLinks()
- PhotosAlbumController::albumView in src/
Controller/ PhotosAlbumController.php - Returns an overview of recent albums and photos.
- PhotosLegacyAlbumViewController::view in src/
Controller/ PhotosLegacyAlbumViewController.php - Returns the photos legacy album view.
File
- src/
PhotosAlbum.php, line 334
Class
- PhotosAlbum
- Create an album object.
Namespace
Drupal\photosCode
public static function orderLinks($arg, $count = 0, $link = 0, $limit = 0) {
// @todo move out? This is used in recent images, user images and album.
// @todo move count and order links out.
// Get current path.
$q = \Drupal::service('path.current')
->getPath();
$field = [
'weight' => t('By weight'),
'title' => t('By title'),
'created' => t('By time'),
'comments' => t('By comments'),
'filesize' => t('By filesize'),
];
// Check count image views variable.
$photos_image_count = \Drupal::config('photos.settings')
->get('photos_image_count');
if (!$photos_image_count) {
$field['visits'] = t('By visits');
}
if ($limit) {
$get_limit = \Drupal::request()->query
->get('limit');
$query = PhotosAlbum::getPagerQuery();
$links['limit'] = '';
if (!is_array($limit)) {
$limit = [
5,
10,
20,
30,
40,
50,
];
}
$limit_query = $query;
$limit_count = count($limit);
foreach ($limit as $key => $tt) {
$limit_query['limit'] = $tt;
$sort = [
'query' => $limit_query,
'attributes' => [
'class' => [
isset($get_limit) && $get_limit == $tt ? 'orderac' : NULL,
],
'rel' => 'nofollow',
],
];
$links['limit'] .= Link::fromTextAndUrl($tt, Url::fromUri('base:' . $q, $sort))
->toString();
if ($limit_count != $key) {
$links['limit'] .= ' ';
}
}
}
$links['count'] = $count;
$links['link'] = $link ? $link : NULL;
$sort_links = Link::fromTextAndUrl(t('Default'), Url::fromUri('base:' . $arg, [
'attributes' => [
'rel' => 'nofollow',
],
]))
->toString() . ' ';
$sort_link_count = count($field);
$get_field = \Drupal::request()->query
->get('field');
$get_limit = \Drupal::request()->query
->get('limit');
$get_sort = \Drupal::request()->query
->get('sort');
foreach ($field as $key => $t) {
if (empty($get_field) || $get_field != $key) {
$sort = 'desc';
$class = 'photos-order-desc';
}
elseif ($get_sort == 'desc') {
$sort = 'asc';
$class = 'photos-order-asc photos-active-sort';
}
else {
$sort = 'desc';
$class = 'photos-order-desc photos-active-sort';
}
$field_query = [
'sort' => $sort,
'field' => $key,
];
if ($get_limit) {
$field_query['limit'] = Html::escape($get_limit);
}
$sort_links .= Link::fromTextAndUrl($t, Url::fromUri('base:' . $q, [
'query' => $field_query,
'attributes' => [
'class' => [
$class,
],
'rel' => 'nofollow',
],
]))
->toString();
if ($key != $sort_link_count) {
$sort_links .= ' ';
}
}
if ($sort_links) {
$links['sort'] = [
'#markup' => $sort_links,
];
}
return [
'#theme' => 'photos_album_links',
'#links' => $links,
];
}