You are here

function _entity_translation_element_title_append in Entity Translation 7

Appends the given $suffix string to the title of the given form element.

If the given element does not have a #title attribute, the function is recursively applied to child elements.

1 call to _entity_translation_element_title_append()
entity_translation_element_translatability_clue in ./entity_translation.module
Adds visual clues about the translatability of a field to the given element.

File

./entity_translation.module, line 1469

Code

function _entity_translation_element_title_append(&$element, $suffix) {
  static $fapi_title_elements;

  // Elements which can have a #title attribute according to FAPI Reference.
  if (!isset($fapi_title_elements)) {
    $fapi_title_elements = array_flip(array(
      'checkbox',
      'checkboxes',
      'date',
      'fieldset',
      'file',
      'item',
      'password',
      'password_confirm',
      'radio',
      'radios',
      'select',
      'text_format',
      'textarea',
      'textfield',
      'weight',
    ));
  }

  // Update #title attribute for all elements that are allowed to have a #title
  // attribute according to the Form API Reference. The reason for this check
  // is because some elements have a #title attribute even though it is not
  // rendered, e.g. field containers.
  if (isset($element['#type']) && isset($fapi_title_elements[$element['#type']]) && isset($element['#title'])) {
    $element['#title'] .= $suffix;
  }
  elseif (isset($element['#title']) && isset($element['#cardinality']) && $element['#cardinality'] != 1) {
    $element['#title'] .= $suffix;
  }
  elseif ($children = element_children($element)) {
    foreach ($children as $delta) {
      _entity_translation_element_title_append($element[$delta], $suffix);
    }
  }
  elseif (isset($element['#title'])) {
    $element['#title'] .= $suffix;
  }
}