public function TagService::sortTags in TagCloud 8
Same name and namespace in other branches
- 2.0.x src/TagService.php \Drupal\tagclouds\TagService::sortTags()
- 1.0.x src/TagService.php \Drupal\tagclouds\TagService::sortTags()
Orders a set of tags.
@todo If you feel like making this more modular, please send me patches.
Parameters
array $tags: An array of tag objects.
string $sort_order: (optional) Contains the sort and the order string. Possible values: "title, asc", "title, desc", "count, asc", "count, desc".
Return value
array A list of sorted tag objects.
Overrides TagServiceInterface::sortTags
File
- src/
TagService.php, line 56
Class
- TagService
- Class TagService.
Namespace
Drupal\tagcloudsCode
public function sortTags(array $tags, $sort_order = NULL) {
if ($sort_order == NULL) {
$config = $this->configFactory
->get('tagclouds.settings');
$sort_order = $config
->get('sort_order');
}
list($sort, $order) = explode(',', $sort_order);
switch ($sort) {
case 'title':
usort($tags, "static::sortByTitle");
break;
case 'count':
usort($tags, "static::sortByCount");
break;
case 'random':
shuffle($tags);
break;
}
if ($order == 'desc') {
$tags = array_reverse($tags);
}
return $tags;
}