function soft_length_limit_form_node_form_alter in Soft Length Limit 7
Implements hook_form_FORM_ID_alter().
Adds CSS and JS to display soft_length_limits when they are set for the title field.
File
- ./
soft_length_limit.module, line 239 - Soft Length Limit module
Code
function soft_length_limit_form_node_form_alter(&$form, $form_state) {
$type = $form['#node']->type;
$max_length = variable_get(SOFT_LENGTH_LIMIT_TITLE_MAX . '_' . $type, NULL);
$min_length = variable_get(SOFT_LENGTH_LIMIT_TITLE_MIN . '_' . $type, NULL);
if (!$min_length) {
$min_length = 0;
}
$style_select = variable_get(SOFT_LENGTH_STYLE_SELECT . '_' . $type, NULL);
// Play nice with title module ensuring that core's title is present.
if (isset($form['title']) && (!empty($max_length) || !empty($min_length))) {
$form['title']['#attributes']['class'][] = 'soft-length-limit';
$form['title']['#attributes']['data-soft-length-limit'] = $max_length;
$form['title']['#attributes']['data-soft-length-minimum'] = $min_length;
$form['#attached']['js'][] = drupal_get_path('module', 'soft_length_limit') . '/jquery.textchange.min.js';
$form['#attached']['js'][] = drupal_get_path('module', 'soft_length_limit') . '/soft_length_limit.js';
$form['#attached']['css'][] = drupal_get_path('module', 'soft_length_limit') . '/soft_length_limit.css';
$form['title']['#attributes']['data-soft-length-style-select'] = $style_select;
}
}