2

I've made a custom module that creates a new field type. Any single-cardinality instances of this field work fine. However, multi-cardinality instances of this field will not pass my #element_validate function; see https://drupal.stackexchange.com/questions/86745/element-validate-function-is-called-on-sub-elements-of-a-form-form-items-are-c

Since I don't need this field to ever be multi-value, I want to disable multiple values for this field entirely.

Is there a way to do this?

1 Answer 1

2

Just alter the cardinality selection with this hook and provide only one value:

function <my_module>_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#field']['type'] == '<my_field_type>') {
    $form['field']['cardinality']['#options'] = array(1);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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