How to customize search dropdown?

I’m running Classic 2.7.1 hosted on Reclaim, using the Emiglio theme.

I’ve created customized field labels for the Item display in record-metadata.php.

I’d like to do the same for the field names in the search dropdown. I don’t want to change any of the search functionality, just the display labels in the “Narrow by Specific Fields” dropdown. Which file do I edit for that? I’m not an expert PHP coder, so an example would also help.

The item advanced search form view is at items/search-form.php (within application/views/scripts and copyable to the theme, similar to common/record-metadata.php).

The dropdown for picking an element to search is a $this->formSelect call with the title “Search Field”, and the get_table_options part of that call is the piece that specifically gets the labels and values for the choices in the dropdown. Changing that to something else will change what options are shown on the form.

You have different options for how to change that: the simplest is probably simply hardcoding an array of the choices you want to show there and their labels, as that would accomplish both customizing the labels and tailoring down the choices to your desired options. get_table_options there returns a simple array: the keys are the IDs of each element that can be selected, and the values are the labels for each element.

It’s also possible to just take the dropdown values exactly as they normally are and just change some of the labels.

So this section:

get_table_options(‘Element’, null, array(
‘record_types’ => array(‘Item’, ‘All’),
‘sort’ => ‘orderBySet’)

Since I’m not very good at this, if you can give me an example of how to format one, I’d really appreciate it.

For example, in record-metadata.php, I use:

<?php foreach ($setElements as $elementName => $elementInfo): ?>
<div id="<?php echo text_to_id(html_escape("$setName $elementName")); ?>" class="element">
    <h3>
<?php if($setName=='Dublin Core' && $elementName=='Creator') $elementName="Designed By"; ?> <?php if($setName=='Dublin Core' && $elementName=='Publisher') $elementName="Made By"; ?> <?php if($setName=='Dublin Core' && $elementName=='Subject') $elementName="Worn By"; ?>
        <?php echo html_escape(__($elementName)); ?></h3>
    <?php foreach ($elementInfo['texts'] as $text): ?>
        <div class="element-text"><?php echo $text; ?></div>

(this is a specialized textile/clothing/costume collection with a lot of specialized metadata categories)

I’m not going to be able to tell you how to do this, but I do wonder if an easier solution might have been to create Item Type metadata and then to use the Hide Elements plugin to tuck away the DC fields that you were replacing.

Generally, what you want to do there is pull out the get_table_options call into its own variable, edit that variable to make your desired changes, then use the variable where the call originally was in the code.

/* put this above the $this->formSelect line */
$elementOptions = get_table_options('Element', null, array(
    'record_types' => array('Item', 'All'),
    'sort' => 'orderBySet'
));
$elementOptions[SOME_ID] = 'SOME_LABEL';
/* etc. */

/* then replace the original get_table_options call with just $elementOptions */

SOME_ID in the example is the ID number of the element you want to change the label for. You can find what this is by looking in the database or looking at the HTML source of the current search form: the value of every option in the dropdown is the element’s ID. SOME_LABEL is just the new label you want to use instead. You can repeat that kind of line for as many changes as you want to make.

I ended up following Sharon’s suggestion, which I somehow had never considered before. That worked for me, as the specialized files/labels are in the site interface and appear correctly in the Admin UI. I use the Hide Fields plugin to streamline.

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