You are here

function civicrm_entity_reference_field_form_field_ui_field_edit_form_alter in CiviCRM Entity 7.2

Implements hook_form_FORMID_alter().

form id : field_ui_field_edit_form

Alter Field Settings form to set cardinality to Unlimited, and disable the select widget

Check the "delete reference" inline entity form option if that is the widget

_state

Parameters

$form:

File

modules/civicrm_entity_reference_field/civicrm_entity_reference_field.module, line 42
Provide CiviCRM entity reference field type

Code

function civicrm_entity_reference_field_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  if ($form['#field']['type'] == 'civicrm_entity_reference') {

    // field settings mods
    // Commenting our for now, for cases like location block on events, there is only one value, maybe it doesn't make sense to force 'Unlimited'

    //$form['field']['cardinality']['#default_value'] = -1;

    //$form['field']['cardinality']['#disabled'] = TRUE;
    if ($form['instance']['widget']['type']['#value'] == 'inline_entity_form_single' || $form['instance']['widget']['type']['#value'] == 'inline_entity_form') {

      // Its going to delete the referenced entity so we just set this value to 1 and disable the checkbox to avoid confusion
      // UPDATE: OR not? Cases like Events that have location blocks, don't need to delete the location block when deleting the event?

      //$form['instance']['widget']['settings']['type_settings']['delete_references']['#default_value'] = 1;

      //$form['instance']['widget']['settings']['type_settings']['delete_references']['#disabled'] = TRUE;

      // Does it make sense to have the "add existing entities?" functionality, disabling it for now
      if (isset($form['instance']['widget']['settings']['type_settings']['allow_existing'])) {
        $form['instance']['widget']['settings']['type_settings']['allow_existing']['#default_value'] = 0;
        $form['instance']['widget']['settings']['type_settings']['allow_existing']['#disabled'] = TRUE;
      }
    }
  }
}