I am hoping to create a plugin that filters the all_element_texts
function. I realize there is not currently a filter for the all_element_texts
function. Seems like it would be a useful addition. Here’s my case. I’m hoping to gather some dev help on this and some buy-in from the Omeka team.
Use Case
The use case for such a filter would be to gain programmatic control over the presentation of elements as they’re displayed in most themes. For example, changing the order of elements, omitting or modifying headings for elements and sets, using element texts to build interactive components, combining texts from multiple elements to create a natural language presentation, creating or enabling radically different layouts based on item type, inserting custom content between elements, etc. – basically to inject some new design possibilities into the mix.
Why Not a Theme?
Ideally, plugin-generated functionality should work seamlessly across themes. Generally, site administrators should not need to switch themes just to gain a particular functionality.
Why Not a Hook or Custom View Template?
Related, plugins that hook into themes or provide custom view templates are often at a disadvantage because they cannot predict the outer HTML structure of a given theme, whereas the location of all_element_texts
in a theme is fairly predictable and neutral in terms of where it will sit within a layout. Hooks and alternate view templates are valuable tools but they can’t quite achieve this particular outcome.
Why Not Other Filters?
An alternate option like the Element Display Filter don’t quite address the same need because it does not allow the developer to work with all elements holistically in relation to one another, instead enabling only per-element/set changes before passing the content back as a formatted array. By filtering all_element_texts
on the other hand, the developer can freely manipulate and output element texts in any manner they like.
Are there other filters that might be useful here that I’m just missing?
Adding a New Filter
Just messing around in the core, it seems like it should be easy enough to add a filter using something like what follows:
/** modified source: application/libraries/globals.php **/
function all_element_texts($record, $options = array())
{
$texts = get_view()->allElementTexts($record, $options);
return apply_filters('all_element_texts', $texts);
}
Of course, this specific example returns the $texts
as HTML, which is not helpful for the use case described above. Making significant changes would require passing an array of element sets/texts to the filter. And for that I would need some guidance. Seems like I’d need to modify the $_returnType
for Omeka_View_Helper_AllElementTexts
but only when when using the filter – not exactly sure how to do that. (If I knew, I’d probably have already submitted this as a PR.)
Anyway, I’d love some feedback and/or help on this idea – from the Omeka team as well as from other developers. Cheers.