Hi

I'm not sure whether this is a bug or intended, but no matter what "Maximum length"
I set for my cck input fields it always stays at 128 characters.

Comments

KarenS’s picture

Status: Active » Fixed

This should now be fixed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

szy’s picture

Status: Closed (fixed) » Active

It happens again with CCK Redirection field.

CCK Redirection adds a text type field with max length of 128 characters, even though
length in database is 255. It's not enough for long URL.

I can see that's because of system_elements(), but why is it so short by default?

Drupal 6.8
CCK Redirection 6.x-1.1
Content Construction Kit (CCK) 6.x-2.x-dev (2008-dec.-09) / 6.x-2.1 (2008-nov.-12)

Thanks,
Szy.

Anonymous’s picture

I also have this same problem, How can I change the max length to 255?

Anonymous’s picture

in case anyone else has this problem, it's in the Drupal core code, in the file

modules/system/system.module:
function system_elements():
$type['textfield'] = array(..., '#maxlength' => 128, ...); change to ---> $type['textfield'] = array(..., '#maxlength' => 255, ...);

(don't copy and paste that by the way, the code around #maxlength is just posted for reference purposes so you can find it in the file.)

dawehner’s picture

oh no! don't hack core!!

there are thousands of ways to solve this problem :)
@szd: This is a problem in the code of cck redirection field, but its easy to fix

Anonymous’s picture

it's just changing a 128 to a 255, seems like a work-around wouldn't be worth the trouble. I documented the change in a separate file, so any time there's an update, I just refer to that file to re-do the changes.

dawehner’s picture

anyway thats not good!

you can solve this using hook_form_alter etc.
This is not good what you are doing :)

Anonymous’s picture

it's the only core change I've ever made, I'm not rampantly hacking core, lol.

Anonymous’s picture

actually I tried fixing the code in CCK redirection, and even if you go in and change everything in that module from 128 to 255, it still shows up as 128 because of function system_elements() in the system.module file. That's why you have to change system_elements.

Pasqualle’s picture

any change in core is hacking core. Don't do that, and more importantly do not advise it to others. That is not a solution.
With your fix you probably caused several bugs in your Drupal install, where form elements relies on this value being 128..

szy’s picture

*edited*

Sorry, please remove my post.

Szy.

markus_petrux’s picture

Status: Active » Fixed

Text fields in CCK allow you to define the size of input elements and also the maxlength.

If the issue is related to another field (#3 suggested it was about CCK Redirection? is that anothe module? ), then please open a report to the proper issues queue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

fatcrobat’s picture

Create your own little helper Module and create a hook_form_alter like below.
Core hacking is dirty indeed.


function mymodule_form_alter(&$form, $form_state, $form_id) {
	if($form_id == 'content_field_overview_form'){
		$form['_add_new_field']['label']['#maxlength'] = 255;
		$form['_add_existing_field']['label']['#maxlength'] = 255;
	}
	else if($form_id == 'content_field_edit_form'){
		$form['basic']['label']['#maxlength'] = 255;
	}
}

kenorb’s picture

crazymind’s picture

Good day! I try
"modules/system/system.module:
function system_elements():
$type['textfield'] = array(..., '#maxlength' => 128, ...); change to ---> $type['textfield'] = array(..., '#maxlength' => 255, ...);"
and
"

function mymodule_form_alter(&$form, $form_state, $form_id) {
    if($form_id == 'content_field_overview_form'){
        $form['_add_new_field']['label']['#maxlength'] = 255;
        $form['_add_existing_field']['label']['#maxlength'] = 255;
    }
    else if($form_id == 'content_field_edit_form'){
        $form['basic']['label']['#maxlength'] = 255;
    }
}

"
but it dont work (.
if use hook_form_alter then id do reload page filed settings after changes and dpr($form) then changes ( $form['basic']['label']['#maxlength'] = 255) do not see (((.

html text of the node elements

input id="edit-field-diagnosticum-file-2-data-description" class="form-text" type="text" value="" size="60" name="field_diagnosticum_file[2][data][description]" maxlength="128"

alirezaara’s picture

what is the solution in D7?

dariusa’s picture

For D7, check out what they're doing here: http://drupal.org/project/field_display_label and modify as needed. Basically, the modified code would look like this:



/**
*  Implementation of hook_form_FORM_ID_alter
*/
function your_module_form_field_ui_field_edit_form_alter(&$form, $form_state, $form_id) {
  $form['instance']['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Custom Display label'),
    '#description' => t('Lable to appear in form.'),
    '#default_value' => isset($form['#instance']['display_label']) ? $form['#instance']['display_label'] : '',
    '#weight' => $form['instance']['label']['#weight'] + 1,
    '#maxlength' => 'desired length',
  );
}

/**
*  Implementation of hook_field_display_alter
*/
function your_module_theme_registry_alter(&$theme_registry) {
  $theme_registry['field']['preprocess functions'][] = 'your_module_preprocess_field';
}

/**
*  Preprocess function to replace the regular label with the longer label
*/
function your_module_preprocess_field(&$variables) {
  $field = field_info_instance($variables['element']['#entity_type'], $variables['element']['#field_name'], $variables['element']['#bundle']);
  if (isset($field['display_label']) && strlen(trim($field['display_label'])) > 0) {
    $variables['label'] = $field['label'];
  }
}

ahaomar’s picture

Issue summary: View changes

what the solution for Drupal 8 please