Adding a secondary Collections or ItemSet menu

Hi

I am attempting to add a secondary “Collections” or itemset menu to a theme. I would like the the menu to list just those Item Sets that contain items for each particular site and to sort the item sets alphabetically.

Building on previous advice supplied on this forum I have come up with:-

<?php $siteId = $site->id(); ?>
	<nav id="item-set-menu">
		<ul>
		<?php $itemSets = $this->api()->search('item_sets', ['site_id' => $siteId, 'sort_by' => 'title', 'sort_order' => 'asc'])->getContent(); ?>
		<li>Collections:</li>
		<ul>
		<?php foreach ($itemSets as $itemSet): 
			$itemCount = $itemSet->itemCount(); 
			if ($itemCount > 0): ?>
				<li>
				<?php $fullLink = $itemSet->link($itemSet->displayTitle());
				$href = (string)( new SimpleXMLElement($fullLink))['href'];
				$firstQuote = strpos($fullLink,'href="')+5;
				$secondQuote = strpos($fullLink,'"',$firstQuote+1)+1;
				$finalLink = substr($fullLink,0,$firstQuote) . $href . "?sort_by=title&sort_order=asc";
				$finalLink .= substr($fullLink,$secondQuote);
				echo $finalLink; ?>
				</li>
			<?php endif; ?>
		<?php endforeach; ?>
		</ul>
	</ul>
</nav>

This works (surprisingly) but has issues:

  1. There must be a better way to set the default sort order for when each item set is displayed than having to muck about with the URL, appending the sort_by and sort_order parameters.
  2. I used the itemCount function to determine how many items are in each set, BUT this returns how many items are in the total item set pool, and not how many are associated with a particular site.
  3. I would like the first option in the menu to link to the same Item Set page that you get from the standard options in the navigation menu with a few improvements if possible. The standard Item Set page returns all the item sets in the site’s pool even if it is empty. Again there seems little point listing an empty item set.

One issue I have is trying to determine how to best to invoke some of the function. For example the https://omeka.org/s/docs/developer/modules/view_helpers/ page list many helpers, however few have examples, or any indications of parameters that may be passed. Attempting to find instances within the code is not helpful, for example searching the installation for “searchFilters” returns 610 hits in 51 files.

Many thanks for looking

I take your point on the unhelpfulness of the listing of view helpers there. To aid looking at source code, I can tell you that the code for view helpers lives in the folder application/src/View/Helper: for each of those classes the __invoke function is what you’re actually calling in a view.

We’ll also look at improving the documentation there.

In terms of modifying links, you might want to look at using the url functions for representations rather than the “link” ones, just to avoid parsing HTML to make your change.

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