Is it possible for a plugin to filter the name of an Item Type? Something like below?
In this simple example I’m trying to use the Element Display Filter, which of course doesn’t work. Is there a way to accomplish this functionality (other than at the theme level)?
class myPlugin extends Omeka_Plugin_AbstractPlugin{
protected $_filters = array(
'_test' => array( 'Display', 'ItemType', 'name' ),
)
public function _test($text){
if( !is_admin_theme() && $text = 'Still Image' ){
return 'Awesome Photograph';
}
return $text;
}
}
(PS: Changing the actual name via the admin form is not an option in my use case. This needs to just be on the front end.)
It’s probably going to depend a little on how the theme is getting the item type name to display it.
If it’s using metadata
then the Display
filter should actually work, using array('Display', 'Item', 'item_type_name')
for example, if it’s a call to metadata($item, 'item_type_name')
you want to filter.
Ah, ok, thanks, this is helpful. So to filter instances where the item type name is called using the item object – with either underscores or spaces – might go something like below, which also addresses the name in item search filters.
class myPlugin extends Omeka_Plugin_AbstractPlugin
{
protected $_filters = array(
'item_search_filters',
'_filterItemTypeName' => array('Display', 'Item', 'Item Type Name'),
'_filterItemTypeNameUnderscores' => array('Display', 'Item', 'item_type_name'),
)
public function _filterItemTypeName($text)
{
if(!is_admin_theme() && $text == 'Still Image'){
return 'Awesome Photograph';
}
return $text;
}
public function _filterItemTypeNameUnderscores($text)
{
return $this->_filterItemTypeName($text);
}
public function filterItemSearchFilters($displayArray, $args)
{
foreach($displayArray as $key=>$value){
if($key == 'Item Type'){
if($value == 'Still Image'){
$displayArray[$key] = 'Awesome Photograph';
}
}
}
return $displayArray;
}
}
Yeah unfortunately we are applying the normalization of those “property” names after the filter gets called so currently the exact spacing/underscoring/capitalization used by the theme matters.