Changing collections default sort not working


I’ve started working on a plugin and I was hoping to use the ‘collections_browse_default_sort’ filter to change the default sorting of collections in /collections/browse, but unfortunately nothing happens: the code inside the filter function is completely ignored. The ‘items_browse_default_sort’, in comparison, works like a charm. The version of omeka used is 2.5.1. Is there a chance I can get it to work ? Here is a sample code:

protected $_filters = array('collections_browse_default_sort');

public function filterCollectionsBrowseDefaultSort($sort, $args) {
    var_dump('toto');    <==== does nothing...

Best regards.

That looks like a bug in Omeka.

The fix is in

Basically, go to /application/controllers/CollectionsController.php and completely delete the browseAction function.

Then add this function to the end of the file

    protected function _getBrowseDefaultSort()
        return array('added', 'd');

Thanks, that did the trick.
Is there a way for a plugin to access and change the sort links used in browse_sort_links() ?

That might depend on the details of your needs. Lots of themes skip the wrapperTags parameter, so using that might help. See the docs on it. If the theme you’re working with skips that, that might get you closer to what you need.

If you need something more that that doesn’t supply, you might have to use that function as a model to create a new function to use in your theme.

I need to add or remove elements from the $links array used in browse_sort_links($links, $wrapperTags). I was hoping to do this from my plugin without having to change anything in the default theme, but I don’t see any hooks or filters which could do the job. I guess I can create a filter in my plugin to change the values in the $links array, and use it through apply_filters() in my theme… but that’s extra code in the theme, which is what I wanted to avoid. If I have no other choice, I’ll go with that solution :wink:

@patrickmj, deleting browseAction seems to be creating a problem with the CollectionsBrowseParams filter, as it doesn’t work anymore (though it is still listed as an acceptable one).

What would you suggest to do to fix the problem?

@DanieleB what version of Omeka are you using?

As Patrick’s original post mentioned, this was a bug in Omeka that made the default sort filter not work, but this is fixed in 2.6 and up and requires no core changes in those versions.

We are using version 2.7 at the moment, John.

I’ve checked on GitHub too, and it is the same. Since browseAction is missing, where should CollectionsBrowseParams point to?

I’m not sure I understand the question: in Omeka 2.7, there is no browseAction in the collections controller. Or you’re simply referring to the fact that it isn’t there, not that you deleted it?

There should be no difference in the functioning of the collections_browse_params filter. The code that runs that filter is at a different, lower layer that’s unchanged.

I am indeed referring to the fact that browseAction is not there anymore.

I had installed the DefaultSort plugin, and although working for Items it did not work for Collections; so, I’ve tried to solve the problem, and found out that the plugin was using the CollectionsBrowseParams filter. Such filter seemingly would not work, and thought it was because the browseAction had been removed. Now that you say it’s still run at a different level, I will investigate more and try to find the reason of its behaviour.

[update] There was a double bug in the plugin, that was creating the odd behaviour. Now everything seems to be working fine. Thanks for helping me finding out.

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.