src/Forms/SortableUploadField.php
protected function sortManyManyRelation(
        ManyManyList $relation,
        array $idList,
        array $rawList,
        DataObjectInterface $record,
        $sortColumn
    ) {
        $relation->getForeignID();
        $ownerIdField = $relation->getForeignKey();
        $fileIdField = $relation->getLocalKey();
        $joinTable = '"' . $relation->getJoinTable() . '"';
        $sort = 0;
        foreach ($rawList as $id) {
            if (in_array($id, $idList)) {
                // Use SQLUpdate to update the data in the join-table.
                // This is safe to do, since new records have already been written to the DB in the
                // parent::saveInto call.
                SQLUpdate::create($joinTable)
                    ->setWhere([
                        "\"$ownerIdField\" = ?" => $record->ID,
                        "\"$fileIdField\" = ?" => $id
                    ])
                    ->assign($sortColumn, $sort++)
                    ->execute();
            }
        }
    }
protected function sortManyManyRelation(
        ManyManyList $relation,
        array $idList,
        array $rawList,
        DataObjectInterface $record,
        $sortColumn
    ) {
        $relation->getForeignID();
        $ownerIdField = $relation->getForeignKey();
        $fileIdField = $relation->getLocalKey();
        $joinTable = '"' . $relation->getJoinTable() . '"';
        $sort = 0;
        foreach ($rawList as $id) {
            if (in_array($id, $idList)) {
                // Use SQLUpdate to update the data in the join-table.
                // This is safe to do, since new records have already been written to the DB in the
                // parent::saveInto call.
                SQLUpdate::create($joinTable)
                    ->setWhere([
                        "\"$ownerIdField\" = ?" => $record->ID,
                        "\"$fileIdField\" = ?" => $id
                    ])
                    ->assign($sortColumn, $sort++)
                    ->execute();
            }
        }
    }
protected function sortManyManyRelation ( ManyManyList $ relation , array $ idList , array $ rawList , DataObjectInterface $ record , $ sortColumn ) { $ relation -> getForeignID ( ) ; $ ownerIdField = $ relation -> getForeignKey ( ) ; $ fileIdField = $ relation -> getLocalKey ( ) ; $ joinTable = '"' . $ relation -> getJoinTable ( ) . '"' ; $ sort = 0 ; foreach ( $ rawList as $ id ) { if ( in_array ( $ id , $ idList ) ) { // Use SQLUpdate to update the data in the join-table. // This is safe to do, since new records have already been written to the DB in the // parent::saveInto call. SQLUpdate :: create ( $ joinTable ) -> setWhere ( [ "\"$ownerIdField\" = ?" => $ record -> ID , "\"$fileIdField\" = ?" => $ id ] ) -> assign ( $ sortColumn , $ sort ++ ) -> execute ( ) ; } } }
Apply sorting to a many_many relation
@param ManyManyList $relation
@param array $idList
@param array $rawList
@param DataObjectInterface $record
@param $sortColumn
Apply sorting to a many_many relation