I would like to be able to make more specific CSS changes to some create form elements, but there isn't much specificity in Drupal's elements.

Specifically, I am looking for how to hook into the function where the class names are written for the taxonomy SELECT element, and insert additional class names into the taxonomy elements. (

For example, instead of just this appearing in the element:
class="form-select required"

I want to output this:
class=" form-select required select-terms"

I assume I can hook some function in template.php of my theme, but I just can't find the function to hook, nor do I know just how to do it. I'm more a designer than a programmer, but i can make do, if someone could be nice enough to give me a fairly explicit example or doc reference.

Thanks in advance.

FYI. This is an example of what gets output now, for just one fieldset containing the taxonomy select elements"

Vocabularies

Topic-sections:
* Goverment
Politics

Comments

droogie’s picture

I guess I have no edit rights to my posts? Weird. Here's the example I forgot to wrap with a code tag above:

<fieldset class=" collapsible"><legend>Vocabularies</legend><div class="form-item" id="edit-taxonomy-3-wrapper">
 <label for="edit-taxonomy-3">topic-sections: <span class="form-required" title="This field is required.">*</span></label>

 <select name="taxonomy[3][]" multiple="multiple"  class="form-select required" id="edit-taxonomy-3"  size="4"><option value="8">Goverment</option><option value="5">Politics</option><option value="7" selected="selected">Religion</option><option value="6">Sports</option></select>
</div>
dvessel’s picture

I think the override you want here is theme_taxonomy_term_select.

What you need to do is to override the element and push the class through #attributes like so:

function phptemplate_taxonomy_term_select($element) {
  if (isset($element['#attributes']['class'])) {
    $element['#attributes']['class'] .= ' select-terms';
  }
  else {
    $element['#attributes']['class'] = 'select-terms';
  }

  return theme('select', $element);
}

Should work, untested.

joon park

droogie’s picture

Thanks. Looks like that is indeed what I wanted. Will test when i get back there.

robcourt’s picture

Hi, i'm looking to change the wording 'Vocabularies' to 'Activities' and i'm not sure how to do this, Do i use the PHP work around you were advised to use?

Here's where it appears:



Vocabularies

Many thanks in advance.

Rob