src/Twig/ArrayExtension.php
/**
     * Helper function for sorting an array of Content.
     */
Helper function for sorting an array of Content.
Helper function for sorting an array of Content .
private function orderHelper(Content $a, Content $b, string $orderOn, bool $orderAscending, string $locale): int
    {
        $aVal = $this->contentHelper->get($a, sprintf('{%s}', $orderOn), $locale);
        $bVal = $this->contentHelper->get($b, sprintf('{%s}', $orderOn), $locale);
        if ($a->getDefinition()->get('fields')->get($orderOn, null) &&
            $a->getDefinition()->get('fields')->get($orderOn)->get('type') === NumberField::TYPE) {
            $aVal = (int) $aVal;
            $bVal = (int) $bVal;
        } elseif (strtotime($aVal) && strtotime($bVal)) {
            $aVal = Carbon::createFromTimestamp(strtotime($aVal));
            $bVal = Carbon::createFromTimestamp(strtotime($bVal));
        }
        if ($orderAscending) {
            return $aVal <=> $bVal;
        }
        return $bVal <=> $aVal;
    }
private function orderHelper ( Content $ a , Content $ b , string $ orderOn , bool $ orderAscending , string $ locale ) : int { $ aVal = $ this -> contentHelper -> get ( $ a , sprintf ( '{%s}' , $ orderOn ) , $ locale ) ; $ bVal = $ this -> contentHelper -> get ( $ b , sprintf ( '{%s}' , $ orderOn ) , $ locale ) ; if ( $ a -> getDefinition ( ) -> get ( 'fields' ) -> get ( $ orderOn , null ) && $ a -> getDefinition ( ) -> get ( 'fields' ) -> get ( $ orderOn ) -> get ( 'type' ) === NumberField :: TYPE ) { $ aVal = ( int ) $ aVal ; $ bVal = ( int ) $ bVal ; } elseif ( strtotime ( $ aVal ) && strtotime ( $ bVal ) ) { $ aVal = Carbon :: createFromTimestamp ( strtotime ( $ aVal ) ) ; $ bVal = Carbon :: createFromTimestamp ( strtotime ( $ bVal ) ) ; } if ( $ orderAscending ) { return $ aVal <=> $ bVal ; } return $ bVal <=> $ aVal ; }
Helper function for sorting an array of Content.
Helper function for sorting an array of Content .
// If the values look like dates, convert them to proper date objects. // Check the primary sorting criterion.