Hi everyone.
One of our librarians pointed out that it would be better to have metadata fields arranged differently, at least on the public side of the repository.
The normal solution, as pointed out in several threads, is to hardcode the fields’ order; but we felt that’s quite a long work to do, especially if one is going to keep all fields (just rearranged in order).
So, I’ve come up with a function that can be fed with an array of fields that need to be shown first, and result in those fields (in the given order) followed by all other fields (in original order):
// define couples of element set / element field
$firstFields = array(array('Dublin Core','Title'), array('Dublin Core','Description'));
$firstElements = array();
foreach ($firstFields as $firstField) {
foreach ($elementsForDisplay as $setName => $setElements) {
foreach ($setElements as $elementName => $elementInfo) {
if ($setName == $firstField[0] && $elementName == $firstField[1]) {
$firstElements[$setName][$elementName] = $elementInfo;
unset($elementsForDisplay[$setName][$elementName]);
}
}
}
}
$elementsForDisplay = array_merge_recursive($firstElements, $elementsForDisplay);
I’ve put this function in my theme’s record-metadata.php
file, in the beginning, et voilà.
Hope this code can help other developers. As usual, there’s some space for improvements (anybody willing to work on them is more than welcome):
- create a plugin that let choose the order of the elements (it could be an improvement of Hide Elements plugin, f.i., or a stand-alone one); a drag and drop interface would be great;
- enable rearrangement also for the Admin interface.