Skip to content

Commit acf8c72

Browse files
committed
Move the trigger of the initialized event in grid views
This is necessary in order to be able to add additional filters or sorting options per event.
1 parent 1d0dd2e commit acf8c72

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

wcfsetup/install/files/lib/system/gridView/AbstractGridView.class.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,6 @@ public function getBaseUrl(): string
461461
*/
462462
public function setSortField(string $sortField): void
463463
{
464-
if (!\in_array($sortField, \array_map(fn($column) => $column->getID(), $this->getSortableColumns()))) {
465-
throw new \InvalidArgumentException("Invalid value '{$sortField}' as sort field given.");
466-
}
467-
468464
$this->sortField = $sortField;
469465
}
470466

@@ -652,6 +648,16 @@ protected function fireInitializedEvent(): void
652648
*/
653649
protected function validate(): void
654650
{
651+
if ($this->getSortField()) {
652+
if (!\in_array($this->getSortField(), \array_map(fn($column) => $column->getID(), $this->getSortableColumns()))) {
653+
if (\ENABLE_DEBUG_MODE) {
654+
throw new \InvalidArgumentException("Invalid value '{$this->getSortField()}' as sort field given.");
655+
} {
656+
$this->setSortField('');
657+
}
658+
}
659+
}
660+
655661
$titleColumn = null;
656662

657663
foreach ($this->getColumns() as $column) {
@@ -746,6 +752,9 @@ public function isSortedBy(GridViewColumn $column): bool
746752
protected function initObjectList(): void
747753
{
748754
$this->objectList = $this->createObjectList();
755+
$this->fireInitializedEvent();
756+
$this->validate();
757+
749758
$this->objectList->sqlLimit = $this->getRowsPerPage();
750759
$this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getRowsPerPage();
751760
if ($this->getSortField()) {
@@ -766,9 +775,8 @@ protected function initObjectList(): void
766775
[$this->getObjectIDFilter()]
767776
);
768777
}
778+
769779
$this->applyFilters();
770-
$this->validate();
771-
$this->fireInitializedEvent();
772780
}
773781

774782
/**

0 commit comments

Comments
 (0)