You are here

function form_placeholder_attach in Form Placeholder 7

Same name and namespace in other branches
  1. 8 form_placeholder.module \form_placeholder_attach()

Adds placeholder to form element.

Parameters

array $element: Form API element.

1 call to form_placeholder_attach()
form_placeholder_process_element in ./form_placeholder.module
Element process callback.

File

./form_placeholder.module, line 110
Use field label as placeholder for all elements in choosen form.

Code

function form_placeholder_attach(&$element) {

  // Adding jQuery Placeholder plugin library.
  if (module_exists('libraries') && ($path = libraries_get_path('jquery.placeholder'))) {
    $element['#attached']['js'][] = array(
      'type' => 'file',
      'data' => $path . '/jquery.placeholder.js',
    );
    $fallback_support = TRUE;
  }
  else {
    $fallback_support = FALSE;
  }

  // Adding settings.
  $whitechars = array(
    "\r\n",
    "\r",
    "\n",
  );
  $element['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array(
      'form_placeholder' => array(
        'fallback_support' => $fallback_support,
        'include' => str_replace($whitechars, ',', variable_get('form_placeholder_include', '')),
        'exclude' => str_replace($whitechars, ',', variable_get('form_placeholder_exclude', '')),
        'required_indicator' => variable_get('form_placeholder_required_indicator', 'append'),
      ),
    ),
  );

  // Adding module JS file.
  $element['#attached']['js'][] = array(
    'type' => 'file',
    'data' => drupal_get_path('module', 'form_placeholder') . '/form_placeholder.js',
  );
}