13th April 2015
Drupal: Setting a higher value for a multi-value field
Lead Developer
When setting up a multi-valued field in Drupal you have the option of either having unlimited values of a fixed nunber of values. For the fixed number, you only get the option of having between 1 and 10 values.
Column:
Image:
Text:
But what if you need to have a fixed value of items higher than 10?
Well there's a hook for that.
Using the hook 'hook_form_FORM_ID_alter' you can override this value for specify a higher range of values.
Color:
#ffffff
Text Color:
Dark
Format:
Image left of text
Image shape:
Square
/** * Implements hook_form_FORM_ID_alter(). */ function MYMODULE_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) { $form['field']['cardinality']['#options'] = array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 20)); }
Now you can select a value between 1 & 20 for any multi-valued fields on your site.