Skip to content

Commit 37c54e2

Browse files
author
johannes sommer
committed
[FEATURE] add mm_sorting_field setting to define field for mm sorting
1 parent 020d743 commit 37c54e2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Classes/DataProcessing/RelationProcessor.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
3535
$table = $cObj->getCurrentTable();
3636
$uid = $cObj->data['uid'];
3737
$field = $processorConfiguration['field'];
38+
$sorting = $processorConfiguration['mm_sorting_field'] ?? '';
3839

39-
$relations = $this->getRelation($cObj, $table, $field, $uid);
40+
$relations = $this->getRelation($cObj, $table, $field, $uid, $sorting);
4041
$request = $cObj->getRequest();
4142
$processedRecordVariables = [];
4243

@@ -58,7 +59,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
5859
/**
5960
* @return list<array<string, string|int|float|bool>>
6061
*/
61-
public function getRelation(ContentObjectRenderer $cObj, string $table, string $field, int $uid): array
62+
public function getRelation(ContentObjectRenderer $cObj, string $table, string $field, int $uid, string $sorting): array
6263
{
6364
$tcaConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'] ?? throw new RuntimeException(
6465
'TCA config for ' . $table . '.' . $field . ' not found'
@@ -101,7 +102,9 @@ public function getRelation(ContentObjectRenderer $cObj, string $table, string $
101102
->from($foreignTable, 'relation')
102103
->join('relation', $mmTable, 'mm', $queryBuilder->expr()->eq('relation.uid', 'mm.' . $otherField))
103104
->where($queryBuilder->expr()->eq('mm.' . $selfField, $uid));
104-
105+
if ($sorting) {
106+
$queryBuilder->orderBy($sorting);
107+
}
105108

106109
$transOrigPointerField = $GLOBALS['TCA'][$foreignTable]['ctrl']['transOrigPointerField'] ?? null;
107110
if ($transOrigPointerField) {

0 commit comments

Comments
 (0)