Set Default Sort in Theme or fix Default Sort plugin

Howdy!

The theme I developed for a friend is working great and I just modified items/browse.php to include the sort fields she wants. The problem is the default sort is Date Added which isn’t a field she wants to include (Title, Date and Subject are her choices).

As I can find no documentation of how to modify browse.php to set the default sort I turned to GitHub - anuragji/DefaultSort: Omeka Plugin to set the default sort for Browse Items and Browse Collections as the lone searchable solution. Unfortunately this plugin fails on its settings page so there is no save option even though the other fields display fine:

Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, false given in V:\dev\icggallery\omeka\Apache24\htdocs\plugins\DefaultSort\config_form.php:153 Stack trace: #0 V:\dev\icggallery\omeka\Apache24\htdocs\plugins\DefaultSort\config_form.php(153): in_array(1, false) #1 V:\dev\icggallery\omeka\Apache24\htdocs\plugins\DefaultSort\DefaultSortPlugin.php(68): include('V:\\dev\\icggalle...') #2 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Omeka\Plugin\Broker.php(142): DefaultSortPlugin->hookConfigForm(Array) #3 V:\dev\icggallery\omeka\Apache24\htdocs\admin\themes\default\plugins\config.php(8): Omeka_Plugin_Broker->callHook('config_form', Array, Object(Plugin)) #4 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Omeka\View.php(114): include('V:\\dev\\icggalle...') #5 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\View\Abstract.php(889): Omeka_View->_run('V:\\dev\\icggalle...') #6 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Action\Helper\ViewRenderer.php(912): Zend_View_Abstract->render(NULL) #7 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Action\Helper\ViewRenderer.php(933): Zend_Controller_Action_Helper_ViewRenderer->renderScript('plugins/config....', NULL) #8 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Action\Helper\ViewRenderer.php(972): Zend_Controller_Action_Helper_ViewRenderer->render() #9 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Action\HelperBroker.php(277): Zend_Controller_Action_Helper_ViewRenderer->postDispatch() #10 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Action.php(527): Zend_Controller_Action_HelperBroker->notifyPostDispatch() #11 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Dispatcher\Standard.php(308): Zend_Controller_Action->dispatch('configAction') #12 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #13 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Application\Bootstrap\Bootstrap.php(106): Zend_Controller_Front->dispatch() #14 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Zend\Application.php(384): Zend_Application_Bootstrap_Bootstrap->run() #15 V:\dev\icggallery\omeka\Apache24\htdocs\application\libraries\Omeka\Application.php(73): Zend_Application->run() #16 V:\dev\icggallery\omeka\Apache24\htdocs\admin\index.php(28): Omeka_Application->run() #17 {main} thrown in V:\dev\icggallery\omeka\Apache24\htdocs\plugins\DefaultSort\config_form.php on line 153

I would prefer a simple bit of PHP code I could put in the theme file that says if no query arguments to set sorting are present use this field as default. If that is somehow not possible does anyone have a working plugin that let’s me set the default sort field for items?

Thanks,
Chris

I think the DefaultSort plugin is no longer being updated and is probably not a viable option. That’s assuming it’s this one, which has not been updated in 5+ years and targets an older version of Omeka.

It sounds like maybe you know already that you can pass an array to browse_sort_links() on the items/browse.php template to define alternate sorting options, but others who find this thread may see below. That’s the first step.

<?php echo browse_sort_links(array(
    __('Subject')=> 'Dublin Core,Subject',
    __('Date')=> 'added',
    // ...
));?>

From there the simplest solution is just to edit the primary navigation so that the link to browse items uses something like:

/items/browse?sort_field=Dublin+Core%2CSubject

Not ideal but it works.

If you want a more graceful solution you can create a simple plugin using the items_browse_default_sort filter. Something like below would be a good start. Maybe. (I did not test this).

class NewDefaultSortPlugin extends Omeka_Plugin_AbstractPlugin {
	protected $_filters = array(
		'items_browse_default_sort',
	);
	
	public function itemsBrowseDefaultSort($sortArray) {
		$sortArray = array('Dublin Core,Subject', 'a');
		return $sortArray;
	}
}

As far as I am aware there is no drop-in code you can add to your theme that will just do this without using plugins.

1 Like