You are here

function _uuidreference_add_target_bundle_elements in UUID reference field 7

Helper function to add the target_bundles build array to a form element.

Parameters

$element:

$form_state:

$target_type:

$entity_info:

1 call to _uuidreference_add_target_bundle_elements()
uuidreference_form_alter in ./uuidreference.module
Implements hook_form_FORM_ID_alter().

File

./uuidreference.module, line 181

Code

function _uuidreference_add_target_bundle_elements(&$element, &$form_state, $target_type, $field, $entity_info) {
  if (!empty($entity_info[$target_type]['entity keys']['bundle'])) {
    $bundles = array();
    foreach ($entity_info[$target_type]['bundles'] as $bundle_name => $bundle_info) {
      $bundles[$bundle_name] = $bundle_info['label'];
    }
    $element['target_bundles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Target bundles'),
      '#options' => $bundles,
      '#default_value' => $field['settings']['target_bundles'],
      '#size' => 6,
      '#multiple' => TRUE,
      '#description' => t('The bundles of the entity type that can be referenced. Optional, leave empty for all bundles.'),
      '#prefix' => '<div id="uuidreference-field-settings-bundles">',
      '#suffix' => '</div>',
    );
  }
  else {
    $element['target_bundles'] = array(
      '#type' => 'value',
      '#value' => array(),
      '#prefix' => '<div id="uuidreference-field-settings-bundles">',
      '#suffix' => '</div>',
    );
  }
}