3.1 Admin Dashboard Stats Filter

As of 3.1, there appears to be a bug in the admin_dashboard_stats filter, at least when used by plugins as directed via the documentation. Here’s what the output looks like.

Output for Items

<p><a href="/admin/items" class="stat"><span class="number">9</span><br>items</a></p>

Output for Exhibit Builder (similar to other plugins)

<p><a href="/admin/1" class="stat"><span class="number"></span></a><a href="/admin/exhibits">0</a><br>exhibits</p>

Note the incorrect URL for the outer link tag and the differing/incorrect markup.

To simplify, here’s a stripped down example using a few different variations.

public function filterAdminDashboardStats( $stats )
{
  $stats[] = array(5, '<a href="ipsum">Records</a>'); 
  $stats[] = array('<a href="lorem">5</a>', 'Records');
  $stats[] = array('<a href="lorem">5</a>', '<a href="ipsum">Records</a>');
  return $stats;
}

None of these display correctly. The first one is close, but the outer link is incorrect (admin/0).

What is the correct usage for this filter as of the current version of Omeka Classic? Is this a bug or am I just using it wrong?

Hmm yes, the way this filter needs to work has changed in 3.1… The new version of this has you pass a couple pieces of data, but not actually create the link yourself.

What it’s looking for now is:

$stats['exhibits'] = array(5, __('exhibits'));

where the first 'exhibits' is a record type to be passed to link_to, and the array is the number followed by the visible label.

The pattern is pretty simple as long as the link you want to put in there can work with the link_to function. Does that match what you want to do here, or not?

This change was made to improve the accessibility of those links, so the number and the label would both be part of the same link, but I don’t think it was quite appreciated at the time that this would change what plugins needed to do here.

Yeah, this works fine for me, thanks!

public function filterAdminDashboardStats( $stats )
{
	if( is_allowed( 'TourBuilder_Tours', 'browse' ) )
	{
		if(version_compare(OMEKA_VERSION,'3.1') >= 0){
			$stats['tours'] = array(total_records( 'Tours' ), __('tours') );
		}else{
			$stats[] = array( link_to( 'tours', array(), total_records( 'Tours' ) ), __('tours') );
		}
	}
	return $stats;
}

We’ll get the documentation for the filter updated to reflect the change here.

1 Like

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