You are here

function relation_dummy_field_field_instance_settings_form in Relation 7

Same name and namespace in other branches
  1. 8 relation_dummy_field/relation_dummy_field.module \relation_dummy_field_field_instance_settings_form()

Implements hook_field_instance_settings_form().

File

relation_dummy_field/relation_dummy_field.module, line 34
A field storing arbitrary relations between entities.

Code

function relation_dummy_field_field_instance_settings_form($field, $instance) {
  $relation_types = relation_get_types();
  $bundle_key = $instance['entity_type'] . ':' . $instance['bundle'];
  $bundle_wildcard_key = $instance['entity_type'] . ':' . '*';
  $options = array();
  foreach ($relation_types as $relation_type => $relation_type_data) {
    foreach (array_unique(array_merge($relation_type_data->source_bundles, $relation_type_data->target_bundles)) as $relation_bundle_key) {

      // We can't currently select only source or only target for directional
      // relations. See TODO:SINGLE_DIR
      if ($bundle_key == $relation_bundle_key || $bundle_wildcard_key == $relation_bundle_key) {
        $options[$relation_type] = $relation_type_data->label;
      }
    }
  }
  $form['relation_type'] = array(
    '#type' => 'select',
    '#title' => t('Relation types'),
    '#description' => t('Select all the relation types you want to display in the dummy field. Only relation types applicable to this entity bundle are show here. If no relation_types are selected, relations of all types will be displayed.'),
    '#default_value' => $instance['settings']['relation_type'],
    '#options' => $options,
    '#multiple' => TRUE,
  );
  return $form;
}