Skip to content

Commit

Permalink
[FEATURE] add mm_sorting_field setting to define field for mm sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes sommer committed Jan 25, 2024
1 parent 020d743 commit 37c54e2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Classes/DataProcessing/RelationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$table = $cObj->getCurrentTable();
$uid = $cObj->data['uid'];
$field = $processorConfiguration['field'];
$sorting = $processorConfiguration['mm_sorting_field'] ?? '';

$relations = $this->getRelation($cObj, $table, $field, $uid);
$relations = $this->getRelation($cObj, $table, $field, $uid, $sorting);
$request = $cObj->getRequest();
$processedRecordVariables = [];

Expand All @@ -58,7 +59,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
/**
* @return list<array<string, string|int|float|bool>>
*/
public function getRelation(ContentObjectRenderer $cObj, string $table, string $field, int $uid): array
public function getRelation(ContentObjectRenderer $cObj, string $table, string $field, int $uid, string $sorting): array
{
$tcaConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'] ?? throw new RuntimeException(
'TCA config for ' . $table . '.' . $field . ' not found'
Expand Down Expand Up @@ -101,7 +102,9 @@ public function getRelation(ContentObjectRenderer $cObj, string $table, string $
->from($foreignTable, 'relation')
->join('relation', $mmTable, 'mm', $queryBuilder->expr()->eq('relation.uid', 'mm.' . $otherField))
->where($queryBuilder->expr()->eq('mm.' . $selfField, $uid));

if ($sorting) {
$queryBuilder->orderBy($sorting);
}

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

0 comments on commit 37c54e2

Please sign in to comment.