src/Twig/ArrayExtension.php
/**
     * Sorts / orders items of an array.
     */
Sorts / orders items of an array.
Sorts / orders items of an array .
public function order(Environment $twig, $array, string $on = '-publishedAt', ?string $onSecondary = null, $locale = null): array
    {
        $array = $this->getArray($array);
        if (! $locale) {
            $locale = ! empty($this->localeExtension->getHtmlLang($twig)) ?
                $this->localeExtension->getHtmlLang($twig) : $this->defaultLocale;
        }
        [$orderOn, $orderAscending] = self::getSortOrder($on);
        [$orderOnSecondary, $orderAscendingSecondary] = self::getSortOrder($onSecondary);
        uasort($array, function ($a, $b) use ($orderOn, $orderAscending, $orderOnSecondary, $orderAscendingSecondary, $locale): int {
            $check = $this->orderHelper($a, $b, $orderOn, $orderAscending, $locale);
            if ($check !== 0 || $orderOnSecondary !== '') {
                return $check;
            }
            return $this->orderHelper($a, $b, $orderOnSecondary, $orderAscendingSecondary, $locale);
        });
        return $array;
    }
public function order ( Environment $ twig , $ array , string $ on = '-publishedAt' , ? string $ onSecondary = null , $ locale = null ) : array { $ array = $ this -> getArray ( $ array ) ; if ( ! $ locale ) { $ locale = ! empty ( $ this -> localeExtension -> getHtmlLang ( $ twig ) ) ? $ this -> localeExtension -> getHtmlLang ( $ twig ) : $ this -> defaultLocale ; } [ $ orderOn , $ orderAscending ] = self :: getSortOrder ( $ on ) ; [ $ orderOnSecondary , $ orderAscendingSecondary ] = self :: getSortOrder ( $ onSecondary ) ; uasort ( $ array , function ( $ a , $ b ) use ( $ orderOn , $ orderAscending , $ orderOnSecondary , $ orderAscendingSecondary , $ locale ) : int { $ check = $ this -> orderHelper ( $ a , $ b , $ orderOn , $ orderAscending , $ locale ) ; if ( $ check !== 0 || $ orderOnSecondary !== '' ) { return $ check ; } return $ this -> orderHelper ( $ a , $ b , $ orderOnSecondary , $ orderAscendingSecondary , $ locale ) ; } ) ; return $ array ; }
Sorts / orders items of an array.
Sorts / orders items of an array .
// Set the 'orderOn' and 'orderAscending', taking into account things like '-publishedAt'. // Set the secondary order, if any.