You are here

function field_placeholder_field_widget_form_alter in Field placeholder 7.2

Same name and namespace in other branches
  1. 7 field_placeholder.module \field_placeholder_field_widget_form_alter()

Implements hook_field_widget_form_alter().

File

./field_placeholder.module, line 86
Field placeholder module hooks and main functionality.

Code

function field_placeholder_field_widget_form_alter(&$element, &$form_state, $context) {
  if (in_array($context['instance']['widget']['type'], field_placeholder_get_widget_types()) && (!empty($context['instance']['placeholder']) || !empty($context['instance']['use_title_as_placeholder']))) {
    field_placeholder_add_non_html5_support();
    $placeholder = field_placeholder_get_widget($context['instance']['widget']['type']);
    $instance = module_exists('i18n_field_placeholder') ? i18n_string_object_translate('field_instance', $context['instance']) : $context['instance'];
    if (!empty($context['instance']['use_title_as_placeholder'])) {
      $element[$placeholder]['#title_display'] = "invisible";
      $element[$placeholder]['#attributes']['placeholder'] = $instance['label'];
    }
    else {
      $element[$placeholder]['#attributes']['placeholder'] = token_replace($instance['placeholder']);
    }
  }
}