You are here

function relation_migrate_configuration_form in Relation 8

Same name and namespace in other branches
  1. 8.2 relation_migrate/relation_migrate.module \relation_migrate_configuration_form()
  2. 7 relation_migrate/relation_migrate.module \relation_migrate_configuration_form()

Configuration form callback.

1 string reference to 'relation_migrate_configuration_form'
relation_migrate_menu in relation_migrate/relation_migrate.module
Implements hook_menu().

File

relation_migrate/relation_migrate.module, line 30
Migrations between *reference fields and relations.

Code

function relation_migrate_configuration_form($form, &$form_state) {
  $field_types = array(
    'entityreference',
    'taxonomy_term_reference',
    'node_reference',
    'user_reference',
  );
  foreach ($field_types as $field_type_name) {
    $field_type_info = field_info_field_types($field_type_name);
    $fields = field_read_fields(array(
      'type' => $field_type_name,
    ));
    if (!empty($field_type_info) && !empty($fields)) {
      $form[$field_type_name] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($field_type_info['label']),
      );
      $options = array();
      foreach ($fields as $name => $field) {
        $options[$name] = check_plain($name);
      }
      $form[$field_type_name]['relation_migrate_' . $field_type_name . '_fields'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Fields'),
        '#options' => $options,
        '#default_value' => variable_get('relation_migrate_' . $field_type_name . '_fields', array()),
        '#description' => t('Select fields of type %type, that should be migrated to relation entites.', array(
          '%type' => $field_type_info['label'],
        )),
      );
      $form[$field_type_name]['relation_migrate_' . $field_type_name . '_relation_type'] = array(
        '#type' => 'select',
        '#title' => t('Relation type'),
        '#options' => relation_get_relation_types_options(),
        '#default_value' => variable_get('relation_migrate_' . $field_type_name . '_relation_type', NULL),
        '#description' => t('Select relation type that should be used when migrating reference fields.'),
        '#element_validate' => array(
          '_relation_migrate_validate_type',
        ),
      );
      $user = User::load(variable_get('relation_migrate_' . $field_type_name . '_user', 1));
      $form[$field_type_name]['relation_migrate_' . $field_type_name . '_user'] = array(
        '#type' => 'textfield',
        '#title' => t('User'),
        '#default_value' => $user->name,
        '#description' => t('User that should own created relations.'),
        '#autocomplete_path' => 'user/autocomplete',
        '#element_validate' => array(
          '_relation_migrate_uid_validate',
        ),
      );
    }
  }
  return system_settings_form($form);
}