14

I'm setting up a field with multiple values. The maximum fixed amount of values I can configure is 10.

If I want more I have to set this to unlimited.

Is there a way tho set the fixed amount of values on a field to 11 values?

20

The cardinality options are hard-coded into the field_ui_field_edit_form() function using these lines of code:

$form['field']['cardinality'] = array(
  '#type' => 'select',
  '#title' => t('Number of values'),
  '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 10)),
  '#default_value' => $field['cardinality'],
  '#description' => $description,
);

It's the drupal_map_assoc(range(1, 10)) line which is limiting the number to 10.

It doesn't seem that the maximum cardinality is validated (or further limited) anywhere else, though (at least not by core), so it would be pretty easy to offer more options for that value using a form alter hook:

function MYMODULE_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  // Increase the max cardinality to 20
  $range = drupal_map_assoc(range(1, 20));
  $new_options =  array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + $range;

  // Change the options
  $form['field']['cardinality']['#options'] = $new_options;
}

I've just tried this out and it seems to have no side-effects at all. The field system respects any cardinality you set that's higher than 10, and saves it without problem when you edit the field in the admin UI.

0
0

I've used this sandbox project to solve the same issue: https://www.drupal.org/sandbox/ydahi/2421885

It provides a UI to set the range for the number of values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.