Skip to content

Commit

Permalink
[FEATURE] Configurable default ordering in backend module
Browse files Browse the repository at this point in the history
With this feature it is possible to define the default order
field and the default order direction for the backend module.

Refs #1169
  • Loading branch information
derhansen committed Dec 16, 2023
1 parent 85fa822 commit 6d2c900
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
10 changes: 9 additions & 1 deletion Classes/Controller/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,16 @@ public function listAction(?SearchDemand $searchDemand = null, array $overwriteD
$this->beUserSessionService->saveSessionData($sessionData);
}

// Initialize default ordering when no overwriteDemand is available
if (empty($overwriteDemand)) {
$overwriteDemand = [
'orderField' => $this->settings['defaultSorting']['orderField'] ?? 'title',
'orderDirection' => $this->settings['defaultSorting']['orderDirection'] ?? 'asc',
];
}

$eventDemand = GeneralUtility::makeInstance(EventDemand::class);
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand ?? []);
$eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
$eventDemand->setOrderFieldAllowed($this->settings['orderFieldAllowed'] ?? '');
$eventDemand->setSearchDemand($searchDemand);
$eventDemand->setStoragePage((string)$this->pid);
Expand Down
4 changes: 4 additions & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ module.tx_sfeventmgt {
notify = 1
export = 1
}
defaultSorting {
orderField = title
orderDirection = asc
}
pagination {
enablePagination = 1
itemsPerPage = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,57 @@ settings.enabledActions.export

If set to "1", the Export-Action / Icon is shown for events with registration enabled.

settings.defaultSorting.orderField
------------------------------

.. confval:: settings.defaultSorting.orderField

:Type: string
:Default: title

Defines the default field to be used for sorting. When not explicitly
specified, the sorting will be based on the "title" field.

settings.defaultSorting.orderDirection
----------------------------------------

.. confval:: settings.defaultSorting.orderDirection

:Type: string
:Default: asc

Specifies the default order direction. The default value "asc" stands for
ascending order. Can be set to "desc" for descending order.

settings.pagination.enablePagination
------------------------------------

.. confval:: settings.pagination.enablePagination

:Type: int
:Default: 1

Determines whether pagination is enabled (1) or disabled (0). When set to
"1", pagination is used to divide content into separate pages.

settings.pagination.itemsPerPage
--------------------------------

.. confval:: settings.pagination.itemsPerPage

:Type: int
:Default: 10

Specifies the number of items to display on each page when pagination is
enabled. The default setting is 10 items per page.

settings.pagination.maxNumPages
-------------------------------

.. confval:: settings.pagination.maxNumPages

:Type: int
:Default: 10

Sets the maximum number of pages to display in the pagination control.
The default is set to 10 pages.
15 changes: 12 additions & 3 deletions Tests/Unit/Controller/AdministrationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public function listActionDoesNotFetchEventsForStoragePidZero(): void
'searchDemand' => new SearchDemand(),
'orderByFields' => $this->subject->getOrderByFields(),
'orderDirections' => $this->subject->getOrderDirections(),
'overwriteDemand' => null,
'overwriteDemand' => [
'orderField' => 'title',
'orderDirection' => 'asc',
],
'pagination' => null,
];
$this->subject->expects(self::once())->method('initModuleTemplateAndReturnResponse')
Expand Down Expand Up @@ -128,7 +131,10 @@ public function listActionDoesNotFetchEventsForStoragePidZeroAndDemand(): void
'searchDemand' => $searchDemand,
'orderByFields' => $this->subject->getOrderByFields(),
'orderDirections' => $this->subject->getOrderDirections(),
'overwriteDemand' => [],
'overwriteDemand' => [
'orderField' => 'title',
'orderDirection' => 'asc',
],
'pagination' => null,
];
$this->subject->expects(self::once())->method('initModuleTemplateAndReturnResponse')
Expand Down Expand Up @@ -179,7 +185,10 @@ public function listActionFetchesAllEventsForGivenStoragePidAndPassesExpectedVar
'searchDemand' => $searchDemand,
'orderByFields' => $this->subject->getOrderByFields(),
'orderDirections' => $this->subject->getOrderDirections(),
'overwriteDemand' => [],
'overwriteDemand' => [
'orderField' => 'title',
'orderDirection' => 'asc',
],
'pagination' => [],
];
$this->subject->expects(self::once())->method('initModuleTemplateAndReturnResponse')
Expand Down

0 comments on commit 6d2c900

Please sign in to comment.