function form_placeholder_attach in Form Placeholder 8
Same name and namespace in other branches
- 7 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 71 - Use field label as placeholder for all elements in chosen form.
Code
function form_placeholder_attach(&$element) {
$config = \Drupal::config('form_placeholder.settings');
// Adding settings.
$whitechars = [
"\r\n",
"\r",
"\n",
];
$element['#attached']['drupalSettings']['form_placeholder'] = [
'include' => str_replace($whitechars, ',', $config
->get('included_selectors')),
'exclude' => str_replace($whitechars, ',', $config
->get('excluded_selectors')),
'required_indicator' => $config
->get('required_indicator'),
];
// Adding module JS file.
$element['#attached']['library'][] = 'form_placeholder/form_placeholder';
}