Document Library Ordering by Set Order

Hello, I’m pulling my hair out trying to figure out this issue. I have a Document Library block that will not sort by set order no matter what I try. All of the other sort options seem to work but this is 100+ files and it’s important that it displays in the order I have setup in the file set. When I go back into sets, the order is saved properly. In the document library options, I choose to order by set and it doesn’t matter if ‘descending’ is checked, the order does not change on my block.

I’m on 8.5.9 and hesitant to upgrade as I have some custom stuff that could break. Anyone else encounter this issue?

Hello. I tested on 8.5.9 and I can confirm the issue. The code to order by fileset is missing. I am not sure if it’s fixed in the latest version but since you’re not going to update you can fix it easily.

Edit the file concrete\blocks\document_library\controller.php. Around line 251, look for the method setupFolderFileSetFilter()
The method looks like this with my added modification where it says my name “NOUR”

protected function setupFolderFileSetFilter(FolderItemList $list)
{
    $sets = json_decode($this->setIds);

    if (count($sets)) {
        $query = $list->getQueryObject();
        $query->leftJoin('tf', 'FileSetFiles', 'fsf', 'tf.fID = fsf.fID');

        switch ($this->setMode) {
            case 'all':
                // Show files in ALL sets
                $query->andWhere(
                    $query->expr()->orX(
                        'nt.treeNodeTypeHandle = "file_folder"',
                        $query->expr()->in('fsf.fsID', $sets)
                    )
                );
                break;
            case 'any':
            default:
                // Show files in ANY of the sets
                $expr = $query->expr()->orX('nt.treeNodeTypeHandle = "file_folder"');

                foreach ($sets as $set) {
                    $expr->add($query->expr()->eq('fsf.fsID', $set));
                }

                $query->andWhere($expr);
                break;
        }

        // [NOUR added this to deal with fileset order if selected ]
        if ($this->orderBy === "set") {
            $order = $this->displayOrderDesc ? 'desc' : 'asc';
            $query->orderBy('fsf.fsDisplayOrder', $order);
        }
        // [NOUR end of modification]
    }

    return $list;
}

If you ever change your mind and want to update, I suggest you copy the modified file to application\blocks\document_library\controller.php so you won’t lose the fix and it will still be used by the core.

2 Likes

@fridayphoto Trying this out on v9 it looks like the same issue persists there so it would be good to submit an issue so that can get fixed in the core - thx!

@EvanCooper my PR for this issue was merged in v9 it should be available in the next version.

1 Like

Awesome, thanks @mnakalay!

Awesome, thanks @mnakalay @EvanCooper !

Thank you! This works perfectly!