function _maxlength_children in Maxlength 7.3
Recursively add the #maxlength_js and #maxlength properties to the elements of a form.
@todo: This function is currently only working for fieldapi fields.
Parameters
array $element: The form element to start looking for.
array $ms_elements: An associative array of api field elements as returned by field_info_instances() that the #maxlength and #maxlength_js properties should be set, with the field_name as a key and the field_data as the value.
1 call to _maxlength_children()
- maxlength_field_attach_form in ./
maxlength.module - Implements hook_field_attach_form().
File
- ./
maxlength.module, line 162 - Limit the number of characters in textfields and textareas and shows the amount of characters left.
Code
function _maxlength_children(&$element, $ms_elements) {
$bypass =& drupal_static(__FUNCTION__);
// Add "$conf['maxlength_always_for_uid1'] = TRUE;" to settings.php to activate
// for user #1.
if (isset($bypass) && $bypass) {
return;
}
elseif (!isset($bypass)) {
$bypass = $GLOBALS['user']->uid == 1 ? !variable_get('maxlength_always_for_uid1', FALSE) : user_access('bypass maxlength');
}
$children = element_get_visible_children($element);
foreach ($children as $child) {
// Check if the field settings for maxlength_js are set and add the maxlength and the label text.
if (isset($element[$child]['#field_name']) && isset($ms_elements[$element[$child]['#field_name']])) {
$settings = $ms_elements[$element[$child]['#field_name']]['widget']['settings'];
if ($settings['maxlength_js'] > 0) {
_maxlength_add_maxlength_attributes($element[$child], $settings);
if (isset($settings['maxlength_js_enforce']) && $settings['maxlength_js_enforce']) {
$element[$child]['#maxlength_js_enforce'] = TRUE;
}
if (isset($settings['maxlength_js_truncate_html']) && $settings['maxlength_js_truncate_html']) {
$element[$child]['#maxlength_js_truncate_html'] = TRUE;
}
}
if (isset($element[$child]['summary']) && isset($settings['maxlength_js_summary']) && $settings['maxlength_js_summary'] > 0) {
_maxlength_add_maxlength_attributes($element[$child]['summary'], $settings, '_summary');
}
}
_maxlength_children($element[$child], $ms_elements);
}
}