You are here

function theme_bef_checkbox in Better Exposed Filters 7.3

Build a BEF checkbox.

Parameters

array $element: Original <select> element generated by Views.

string $value: Return value of this checkbox option.

string $label: Label of this checkbox option.

bool $selected: Checked or not.

Return value

[type] HTML to render a checkbox.

See also

http://api.drupal.org/api/function/theme_checkbox/7

1 string reference to 'theme_bef_checkbox'
better_exposed_filters_theme in ./better_exposed_filters.module
Implements hook_theme().
2 theme calls to theme_bef_checkbox()
theme_select_as_checkboxes in ./better_exposed_filters.theme
Themes a select element as a set of checkboxes.
theme_select_as_tree in ./better_exposed_filters.theme
Themes a taxonomy-based exposed filter as a nested unordered list.

File

./better_exposed_filters.theme, line 672
Provides theming functions to display exposed forms using different interfaces.

Code

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

  // Custom ID for each checkbox based on the <select>'s original ID.
  $properties = array(
    '#required' => FALSE,
    '#id' => $id,
    '#type' => 'bef-checkbox',
    '#name' => $id,
    '#description' => isset($element['#bef_term_descriptions'][$value]) ? $element['#bef_term_descriptions'][$value] : '',
  );

  // 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]);
  }

  // Unset the name attribute as we are setting it manually.
  unset($element['#attributes']['name']);

  // Unset the multiple attribute as it doesn't apply for checkboxes.
  unset($element['#attributes']['multiple']);
  $checkbox = '<input type="checkbox" ' . 'name="' . $element['#name'] . '[]" ' . 'id="' . $id . '" ' . 'value="' . $value . '" ' . ($selected ? 'checked="checked" ' : '') . drupal_attributes($element['#attributes']) . ' />';
  $properties['#children'] = "{$checkbox} <label class='option' for='{$id}'>{$label}</label>";
  $output = theme('form_element', array(
    'element' => $properties,
  ));
  return $output;
}