You are here

function answers_theme_theme_form_element_label in Answers 7.4

Implements custom form_element_label.

1 string reference to 'answers_theme_theme_form_element_label'
answers_theme_theme_registry_alter in answers_theme/answers_theme.module
Implements hook_theme_registry_alter().

File

answers_theme/answers_theme.module, line 31
The Answers_Theme module.

Code

function answers_theme_theme_form_element_label($variables) {
  $element = $variables['element'];

  // Modifications for answers_theme.
  $filter_help_button = '';
  if (isset($element['#bundle'])) {

    // Add a 'filter-help-button'. This uses jquery to toggle the display of
    // the filter help area.
    if (in_array($element['#bundle'], array(
      'comment_node_answers_answer',
      'comment_node_answers_question',
      'answers_answer',
    ))) {
      $filter_help_button = '<span class="answers-form-filter-help"><a>Help</a></span>';
    }

    // Change the title of the answers form body.
    if ($element['#bundle'] == 'answers_answer') {
      $element['#title'] = t('Enter a new answer');
    }
  }

  // This is also used in the installer, pre-database setup.
  $t = get_t();

  // If title and required marker are both empty, output no label.
  if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#required'])) {
    return '';
  }

  // If the element is required, a required marker is appended to the label.
  $required = !empty($element['#required']) ? theme('form_required_marker', array(
    'element' => $element,
  )) : '';
  $title = filter_xss_admin($element['#title']);
  $attributes = array();

  // Style the label as class option to display inline with the element.
  if ($element['#title_display'] == 'after') {
    $attributes['class'] = 'option';
  }
  elseif ($element['#title_display'] == 'invisible') {
    $attributes['class'] = 'element-invisible';
  }
  if (!empty($element['#id'])) {
    $attributes['for'] = $element['#id'];
  }
  $args = array(
    '!title' => $title,
    '!required' => $required,
    '!filter_help_button' => $filter_help_button,
  );

  // The leading whitespace helps visually separate fields from inline labels.
  return ' <label' . drupal_attributes($attributes) . '>' . $t('!title !required !filter_help_button', $args) . "</label>\n";
}