Skip to content

Commit

Permalink
Implement orderby for filter categories and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kitzberger committed Feb 8, 2024
1 parent 1af4440 commit dace2a8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Classes/EventListener/NewsListActionEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,26 @@ public function __invoke(NewsListActionEvent $event)

$categories2 = $this->getAllRecordsByPid('sys_category', $settings['filterCategories']);
if (!empty($categories2)) {
$extended['categories'] = $this->categoryRepository->findByIdListWithLanguageSupport($categories2);
if ($settings['filterCategoriesOrderBy'] ?? false) {
$categories2order = [
$settings['filterCategoriesOrderBy'] => strtoupper($settings['filterCategoriesOrderDirection'] ?? 'ASC'),
];
} else {
$categories2order = [];
}
$extended['categories'] = $this->categoryRepository->findByIdListWithLanguageSupport($categories2, $categories2order);
}

$tags2 = $this->getAllRecordsByPid('tx_news_domain_model_tag', $settings['filterTags']);
if (!empty($tags2)) {
$extended['tags'] = $this->tagRepository->findByIdList($tags2);
if ($settings['filterTagsOrderBy'] ?? false) {
$tags2order = [
$settings['filterTagsOrderBy'] => strtoupper($settings['filterTagsOrderDirection'] ?? 'ASC'),
];
} else {
$tags2order = [];
}
$extended['tags'] = $this->tagRepository->findByIdList($tags2, $tags2order);
}

$data['extendedVariables'] = $extended;
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ Add the following part to your `News/List.html`:
</fieldset>
</f:form>
```

### Order categories and tags

```typo3_typoscript
plugin.tx_news {
settings {
filterCategoriesOrderBy = title
filterCategoriesOrderDirection = asc
filterTagsOrderBy = title
filterTagsOrderDirection = asc
}
}
```

0 comments on commit dace2a8

Please sign in to comment.