On my site I have a taxonomy vocabulary with image fields attached to terms. I'd like to be able to render exposed filter as checkboxes with corresponding images attached.

I've overridden theme_select_as_checkboxes() and bef_checkbox() functions in template.php in my theme. It works, but looks quite ugly.

Is it possible to come up with a more elegant solution?

Comments

mikeker’s picture

Status: Active » Postponed (maintainer needs more info)

My first impression is that this is a Views issue -- you need to be able to add fields to the display of an exposed filter. But I'm guessing that has as much chance in the Views queue as a snowball in hell... My concern in adding this to BEF is that it's starting to get outside the scope of the project and it would open up a huge can of (support) worms that I don't have the time to deal with right now.

Can you attach what your overridden theme_select_as_checkbox and bef_checkbox() routines? I'd like to see what you did before I dismiss all chances of fixing this... Thanks.

akamaus’s picture

Status: Postponed (maintainer needs more info) » Active

Well, theme_select_as_checkbox was only changed to call my own version of bef_checkbox().

Here it is:

function hitech_bef_checkbox($element, $value, $label, $selected) {
  $value = check_plain($value);
  $label = check_plain($label);
  $id = drupal_html_id($element['#id'] . '-' . $value);

  $term = taxonomy_term_load($value);
  $icon = $term->field_icon['und'][0]['filename'];

  $img = theme('image_style', array('style_name' => 'dedication_icon',
                                    'path' => $icon,
                                    'title' => $label));

  // Custom ID for each checkbox based on the <select>'s original ID
  $properties = array(
    '#required' => FALSE,
    '#id' => $id,
  );

  // Prevent the select-all-none class from cascading to all checkboxes
  if (!empty($element['#attributes']['class'])
      && FALSE !== ($key = array_search('bef-select-all-none', $element['#attributes']['class']))) {
    unset($element['#attributes']['class'][$key]);
  }

  $checkbox = '<input type="checkbox" '
    . 'name="' . $element['#name'] . '[]" '    // brackets are key -- just like select
    . 'id="' . $id . '" '
    . 'value="' . $value . '" '
    . ($selected ? 'checked="checked" ' : '')
    . drupal_attributes($element['#attributes']) . ' />';
  $properties['#children'] = "$checkbox <label class='option' for='$id'> $img <b>$label</b></label>";
  $output = theme('form_element', array('element' => $properties));
  return $output;
}

BTW, it's offtopic, but 'name' attribute is being rendered two times for each <input> element.

Les Lim’s picture

mikeker’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Issue queue cleanup... My apologies for taking so long to address this issue!

I'm sorry, but this is outside the scope of BEF. @Les Lim, a revamp of the theme side of BEF is on my radar, but it's not going to be in the near future. At this point, it may end up being part of the 8.x port.

Thanks!