function maxlength_form_alter in Maxlength 7
Same name and namespace in other branches
- 5.2 maxlength.module \maxlength_form_alter()
- 5 maxlength.module \maxlength_form_alter()
- 6.2 maxlength.module \maxlength_form_alter()
- 6 maxlength.module \maxlength_form_alter()
- 7.3 maxlength.module \maxlength_form_alter()
- 7.2 maxlength.module \maxlength_form_alter()
Implementation of hook_form_alter().
File
- ./
maxlength.module, line 23 - Enables a max length countdown on node body, title and CCK textfields.
Code
function maxlength_form_alter(&$form, &$form_state, $form_id) {
// Editing the content
if (strpos($form['#id'], 'node-form') !== FALSE) {
module_load_include('inc', 'maxlength', 'maxlength');
_maxlength_content_form_alter($form, $form_state, $form_id);
}
elseif ($form_id == 'node_type_form' && isset($form['submission'])) {
module_load_include('inc', 'maxlength', 'maxlength');
_maxlength_content_type_form_alter($form, $form_state, $form_id);
}
elseif ($form_id == 'field_ui_field_edit_form' && isset($form['field']['settings'])) {
if ($form['#field']['type'] == 'text' || $form['#field']['type'] == 'text_long' || $form['#field']['type'] == 'text_with_summary') {
if (($form['#field']['type'] == 'text_long' || $form['#field']['type'] == 'text_with_summary') && empty($form['field']['settings']['max_length'])) {
$field_key = $form['instance']['field_name']['#value'];
if (!(strpos($field_key, 'field_') === 0)) {
$type = isset($form['instance']['bundle']['#value']) ? $form['instance']['bundle']['#value'] : '';
if ($type != '') {
$field_key .= '_' . $type;
}
}
$form['field']['settings']['max_length'] = array(
'#type' => 'textfield',
'#title' => t('Maximum length'),
'#default_value' => variable_get('maxlength_' . $field_key, ''),
'#required' => FALSE,
'#element_validate' => array(
'_element_validate_integer_positive',
),
'#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
);
}
module_load_include('inc', 'maxlength', 'maxlength');
_maxlength_cck_form_alter($form, $form_state, $form_id);
}
}
elseif ($form_id == '_content_admin_field_remove') {
variable_del('maxlength_' . $form['field_name']['#value']);
variable_del('maxlength_' . $form['field_name']['#value'] . '_js');
variable_del('maxlength_' . $form['field_name']['#value'] . '_text');
}
}