Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Maxlength doesn't appear to work with https://drupal.org/project/inline_entity_form
I'm digging into inline_entity_form and maxlength to see how this all works, although, I'm not sure I'll be able to figure this out. I'm wondering if someone has figured this out or it's currently not possible. :)
Comment | File | Size | Author |
---|---|---|---|
#2 | maxlength-ief_title_missing_attributes-2062423-2.patch | 1.35 KB | r-mo |
Comments
Comment #1
thefoo CreditAttribution: thefoo commentedFixed, although I'm not sure how hackery this is or what... but it works:
function maxlength_pre_render($element) {
if (((isset($element['#maxlength']) && $element['#maxlength'] > 0) ||(isset($element['#attributes']['maxlength']) && $element['#attributes']['maxlength'] > 0)) &&
isset($element['#maxlength_js']) && $element['#maxlength_js'] === TRUE) {
isset($element['#maxlength_js']) is returning false because $element['#maxlength_js'] doesn't exist. (Not sure why?)
My fix:
function custom_mods_element_info_alter(&$cache) {
// Add prerender functions to textareas and text fields
$cache['textfield']['#pre_render'][] = 'custom_mods_pre_render';
$cache['textarea']['#pre_render'][] = 'custom_mods_pre_render';
$cache['text_format']['#pre_render'][] = 'custom_mods_pre_render';
}
function custom_mods_pre_render($element) { if (((isset($element['#maxlength']) && $element['#maxlength'] > 0) ||(isset($element['#attributes']['maxlength']) && $element['#attributes']['maxlength'] > 0)) && $element['#id'] == 'edit-field-step-und-form-title') {
$element['#maxlength'] = 100;
$element['#attributes']['maxlength_js_label'][]='@remaining characters remaining';
if ($element['#type'] == 'textarea' && !isset($element['#attributes']['maxlength'])) {
$element['#attributes']['maxlength'] = $element['#maxlength'];
}
$element['#attributes']['class'][] = 'maxlength';
$element['#attached']['js'][] = drupal_get_path('module', 'maxlength') . '/js/maxlength.js';
}
return $element;
}
I had to manually define maxlength and the maxlength label... I know this is not ideal. How can I do this better? Hey, at least I didn't hack the original module. :)
Comment #2
r-mo CreditAttribution: r-mo at CTI Digital commentedHave this issue applying maxlength to node titles with inline entity forms. Patch attached so it does the same logic as for node forms. Other fields seem to behave ok with hook_field_attach_form.
Comment #3
r-mo CreditAttribution: r-mo at CTI Digital commentedComment #4
cedeweyWe are only maintaining the Drupal 7 version of the module for critical security fixes, so I'm marking this Closed (won't fix). Thank you everyone for working on this issue. If you do want to maintain the Drupal 7 version, do reach out. We'd be happy to bring you on board as a maintainer.
I also encourage you, if you haven't already, to upgrade your site to Drupal 8/9. We are actively maintaining that version and you would enjoy all of the other features of the latest version of Drupal.