Guest User

Untitled

a guest
Feb 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. $attributes = array();
  2.  
  3. $attributes = isset($element['#label_attributes'])?$element['#label_attributes']:array();
  4.  
  5. function mymodule_form_element_label($variables) {
  6. $element = $variables['element'];
  7. // This is also used in the installer, pre-database setup.
  8. $t = get_t();
  9.  
  10. // If title and required marker are both empty, output no label.
  11. if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#required'])) {
  12. return '';
  13. }
  14.  
  15. // If the element is required, a required marker is appended to the label.
  16. $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';
  17.  
  18. $title = filter_xss_admin($element['#title']);
  19.  
  20. // NOTE: CHANGED LINE BELOW!
  21. // If there are attributes already, use them. If not, create empty array.
  22. $attributes = isset($element['#label_attributes'])?$element['#label_attributes']:array();
  23.  
  24. // Style the label as class option to display inline with the element.
  25. if ($element['#title_display'] == 'after') {
  26. $attributes['class'] = 'option';
  27. }
  28. // Show label only to screen readers to avoid disruption in visual flows.
  29. elseif ($element['#title_display'] == 'invisible') {
  30. $attributes['class'] = 'element-invisible';
  31. }
  32.  
  33. if (!empty($element['#id'])) {
  34. $attributes['for'] = $element['#id'];
  35. }
  36.  
  37. // The leading whitespace helps visually separate fields from inline labels.
  38. return ' <label' . drupal_attributes($attributes) . '>' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "</label>n";
  39. }
Add Comment
Please, Sign In to add comment