Loading...
 
Skip to main content

Tracker field relations and sorting selectable objects

Status
Open
Subject
Tracker field relations and sorting selectable objects
Version
29.x
master
Category
  • Usability
  • Feature request
Feature
Trackers
Resolution status
New
Submitted by
Bernard Sfez / Tiki Specialist
Lastmod by
Bernard Sfez / Tiki Specialist
Rating
(0)
Description

On a Tiki29 I'm using the trackers feature with the tracker field relations to link between 2 trackers.
If I read the tooltip, the online help and the documentation (https://doc.tiki.org/Relations-Tracker-FieldQuestion) what is working to filter on a tracker should work with the tracker field relation "filter" parameter.

From the tracker list items view, I can use: type=trackeritem&tracker_id=2&_sort=tracker_field_actionsDate
This is working fine.

If I use this (and other variations) within the filter field of the tracker field relations, the html front and to insert/edit an item is broken for the tracker field relation.

I had a look at the code.
At lib/core/Tracker/Field/Relation.php I discovered (and updated the documentation)
By default the objects that can be selected are sorted using "title_asc" unless the "Format" field is not used.

If, in the options of the Relations tracker field, the "Format" field contain something, the option of the multiple select list of objects will use the first field in the "Format" field.

For exemple, using "({tracker_field_actionsDate}) {title}" will tell the sort to use the field "tracker_field_actionsDate".

BUT, the direction will stays "_asc" as this is hardcoded.
It should be possible:

  1. To select more precisely what field(s ?) should be used for sorting the objects
  2. It should be possible to use any direction, _asc or _desc.
Solution
Workaround

My workaround at lib/core/Tracker/Field/Relation.php

before workaround from ligne 242
Copy to clipboard
$format = $this->trackerField->getOption('format'); $sort = 'title_asc'; if (! empty($format)) { if (preg_match('/\{(.*?)\}/', $format, $m)) { $sort = $m[1] . '_asc'; } } $params = [ 'existing' => $data['value'], 'relations' => $data['relations'], 'meta' => json_encode($data['meta']), 'filter' => $filter, 'sort' => $sort, 'format' => $format, 'parent' => $this->trackerField->getOption('parentFilter'), 'parentkey' => $this->trackerField->getOption('parentFilterKey'), ];

after workaround
Copy to clipboard
$sort = 'title_asc'; // First, check if sort is explicitly provided in filter if (!empty($filter)) { // Check if $filter is already an array or needs parsing if (is_array($filter)) { $filterParams = $filter; } else { parse_str($filter, $filterParams); $filter = $filterParams; // Update $filter to be the array } if (!empty($filterParams['_sort'])) { // Use the sort directly from filter (already includes _asc or _desc) $sort = $filterParams['_sort']; // REMOVE _sort from filter array as it's handled separately unset($filterParams['_sort']); $filter = $filterParams; } } // If no sort in filter, derive from format if ($sort === 'title_asc' && !empty($format)) { if (preg_match('/\{(.*?)\}/', $format, $m)) { $sort = $m[1] . '_asc'; } } $params = [ 'existing' => $data['value'], 'relations' => $data['relations'], 'meta' => json_encode($data['meta']), 'filter' => $filter, // Pass as array WITHOUT _sort 'sort' => $sort, // Sort is passed separately 'format' => $format, 'parent' => $this->trackerField->getOption('parentFilter'), 'parentkey' => $this->trackerField->getOption('parentFilterKey'), ];


Then I used in the "Filter" field: type=trackeritem&tracker_id=2&_sort=tracker_field_actionsDate_desc

If it helps...

Importance
5
Easy to solve?
5
Priority
25
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
8890
Created
Thursday 08 January, 2026 09:29:18 UTC
by Bernard Sfez / Tiki Specialist
LastModif
Wednesday 18 February, 2026 10:19:55 UTC


Show PHP error messages