src/Forms/SortableUploadField.php
public function getItems()
    {
        $items = parent::getItems();

        // An ArrayList won't contain our sort-column, thus it has to be sorted by the raw submittal data.
        // This is an issue that's seemingly exclusive to saving SiteConfig.
        if (($items instanceof ArrayList) && !empty($this->rawSubmittal)) {
            // flip the array, so that we can look up index by ID
            $sortLookup = array_flip($this->rawSubmittal);
            $itemsArray = $items->toArray();
            usort($itemsArray, function ($itemA, $itemB) use ($sortLookup) {
                if (isset($sortLookup[$itemA->ID]) && isset($sortLookup[$itemB->ID])) {
                    return $sortLookup[$itemA->ID] - $sortLookup[$itemB->ID];
                }
                return 0;
            });

            return ArrayList::create($itemsArray);
        }

        if ($items instanceof Sortable) {
            return $items->sort([$this->getSortColumn() => 'ASC', 'ID' => 'ASC']);
        }

        return $items;
    }
public function getItems()
    {
        $items = parent::getItems();

        // An ArrayList won't contain our sort-column, thus it has to be sorted by the raw submittal data.
        // This is an issue that's seemingly exclusive to saving SiteConfig.
        if (($items instanceof ArrayList) && !empty($this->rawSubmittal)) {
            // flip the array, so that we can look up index by ID
            $sortLookup = array_flip($this->rawSubmittal);
            $itemsArray = $items->toArray();
            usort($itemsArray, function ($itemA, $itemB) use ($sortLookup) {
                if (isset($sortLookup[$itemA->ID]) && isset($sortLookup[$itemB->ID])) {
                    return $sortLookup[$itemA->ID] - $sortLookup[$itemB->ID];
                }
                return 0;
            });

            return ArrayList::create($itemsArray);
        }

        if ($items instanceof Sortable) {
            return $items->sort([$this->getSortColumn() => 'ASC', 'ID' => 'ASC']);
        }

        return $items;
    }
public function getItems ( ) { $ items = parent :: getItems ( ) ; // An ArrayList won't contain our sort-column, thus it has to be sorted by the raw submittal data. // This is an issue that's seemingly exclusive to saving SiteConfig. if ( ( $ items instanceof ArrayList ) && ! empty ( $ this -> rawSubmittal ) ) { // flip the array, so that we can look up index by ID $ sortLookup = array_flip ( $ this -> rawSubmittal ) ; $ itemsArray = $ items -> toArray ( ) ; usort ( $ itemsArray , function ( $ itemA , $ itemB ) use ( $ sortLookup ) { if ( isset ( $ sortLookup [ $ itemA -> ID ] ) && isset ( $ sortLookup [ $ itemB -> ID ] ) ) { return $ sortLookup [ $ itemA -> ID ] - $ sortLookup [ $ itemB -> ID ] ; } return 0 ; } ) ; return ArrayList :: create ( $ itemsArray ) ; } if ( $ items instanceof Sortable ) { return $ items -> sort ( [ $ this -> getSortColumn ( ) => 'ASC' , 'ID' => 'ASC' ] ) ; } return $ items ; }
Return the files in sorted order
@return File[]|SS_List
Return the files in sorted order