Sort metadata fields - an approach

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;
$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.

Drag-and-drop reordering of the elements is already in the admin interface: it’s under Settings -> Element Sets -> Choose “Edit” for your desired element set.

Of course, John, you’re right; completely forgotten about that feature, thanks for pointing it out. Well, I guess my code is kind of useless now :slight_smile:

As we are at it, the page you mentioned could become even more useful if only:

  • fields could be hidden; the Hide Elements plugin is very powerful, as it let you decide where to hide a field, but if someone just wanted to hide them everywhere since they don’t use them, then this would be a good place to put a checkbox to do the job;
  • field brief description could be hidden and/or changed: as it it now, only the “comment” part can be left empty, but if someone wanted a more compact view a chance to hide the short description would be great; same thing for editing it: if I’m not wrong, at the moment it can be done only via translation files or, direclty, in the database;
  • field labels could be changed: I’ve seen many users asking to change the name of some fields, and they always end up having to add some code in order to do it; if one could change the labels here, that would be simpler (original reference to the DC element would have to be preserved, of course).

Just my 2 cents.


update: submitted on GitHub