I'm trying to figure out how I can limit the maximum length of an image title to 40.
I have enabled title from the image field in my content and it works fine except that it seems to take unlimited number of letters. I want to reduce the maximum length of image title to 40.
Does anyone have any idea how to do it?
Thanks
Add a comment
|
1 Answer
Something like this may work:
/**
* Implements hook_field_widget_form_alter
*/
function mymodule_field_widget_form_alter(&$element, &$form_state, $context) {
if ($context['field']['type'] == 'image' && $context['instance']['widget']['type'] == 'image_image' && !empty($context['instance']['settings']['title_field'])) {
foreach (element_children($element) as $delta) {
$element[$delta]['#process'][] = 'mymodule_image_field_widget_process';
}
}
}
/**
* Image field process callback
*/
function mymodule_image_field_widget_process($element, &$form_state, $form) {
// Set title maxlength, if accessible
$maxlength = variable_get('imagefield_maxlength', 40);
if ($element['title']['#access']) {
$element['title']['#maxlength'] = $maxlength;
}
return $element;
}
-
I got this working by editing the image module's image.field.inc file. Changed to '#maxlength' => 100– misamisaCommented Feb 6, 2013 at 3:50
-