Issue Bug Closed

#105015Locale aware sorting of foreign records with selectMultipleSideBySide in the backend

Rémi Payette 09/17/24, 17:47 updated 10/15/24, 09:05

Description

in typo3 v10 and v13, I use a selectMultipleSideBySide to which I set sortItems in the TCA :

'thecolumn' => [
  'exclude' => 0,
  'label' => 'LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:sources',
  'config' => [
    'type' => 'select',
    'sortItems' => [
      'label' => 'asc',
    ],
    'renderType' => 'selectMultipleSideBySide',

The sort order is managed by the PHP function strcasecmp which only does basic ascii comparision which put accented characters at the end of the list.

This is what I have done locally to fix this ( sorry, not equipped to do a proper pull request )

typo3 10.4.45 /backend/Classes/Form/FormDataProvider/TcaSelectItems.php line 288
typo3 13.2.1 /cms-backend/Classes/Form/Processor/SelectItemProcessor.php line 159

    protected function sortItems(array $items, array $sortOrders): array
    {
        foreach ($sortOrders as $order => $direction) {
            switch ($order) {
                case 'label':
                    $direction = strtolower($direction);
*                   $collator = new \Collator(null);
                    @usort(
                        $items,
*                       function ($item1, $item2) use ($direction, $collator) {
                            if ($direction === 'desc') {
*                               return $collator->compare($item1[0], $item2[0]) <= 0;
                            }
*                           return $collator->compare($item1[0], $item2[0]);
                        }
                    );
                    break;

This is the first half of the function in typo3 v10, same changes to the other case ‘value’.
It’s almost the same on typo3 v13.

Reviews 2

History 69

  1. Garvin Hicking changed category 09/17/24, 20:58

  2. Andreas Kienast changed status New Accepted 10/07/24, 11:16

  3. Gerrit Code Review pushed patch set 1 for main to change 86443 status Accepted Under Review 10/07/24, 11:17

  4. Rémi Payette commented 10/07/24, 15:09

    I think the second case on line 176 :

    case 'value':

    should also use the \Collator class to do it’s comparisons

  5. Gerrit Code Review pushed patch set 2 for main to change 86443 10/07/24, 15:16

  6. Gerrit Code Review pushed patch set 1 for 12.4 to change 86552 10/10/24, 18:40

  7. Anonymous commented and changed status Under Review Resolved done 0 % 100 % 10/10/24, 19:05

    Applied in changeset commit:4a0bcf6a3f4e0d5db10a0e519740e760c9c17f5e.

  8. Benni Mack changed status Resolved Closed 10/15/24, 09:05

  9. S P changed Duplicates #95575 10/16/24, 08:15