You are here

function feeds_tamper_efq_finder_form in Feeds Tamper 7

Configuration form.

1 string reference to 'feeds_tamper_efq_finder_form'
efq_finder.inc in plugins/efq_finder.inc

File

plugins/efq_finder.inc, line 20

Code

function feeds_tamper_efq_finder_form($importer, $element_key, array $settings, array &$form_state) {
  $form = array(
    '#prefix' => '<div id="feeds-tamper-efq-finder-wrapper">',
    '#suffix' => '</div>',
  );

  // Get some info on entities and bundles.
  $entity_types = array();
  foreach (entity_get_info() as $machine_name => $info) {
    $entity_types[$machine_name] = check_plain($info['label']);
  }
  $entity_type = _feeds_tamper_efq_finder_get_value('entity_type', $form_state, $settings);
  $form['update'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'feeds_tamper_ui_add_plugin_form_submit',
    ),
    '#value' => t('Update'),
    '#attributes' => array(
      'class' => array(
        'no-js',
      ),
    ),
  );
  $form['entity_type'] = array(
    '#type' => 'select',
    '#title' => t('Entity type'),
    '#options' => $entity_types,
    '#default_value' => $entity_type,
    '#ajax' => array(
      'callback' => 'feeds_tamper_efq_finder_ajax',
      'wrapper' => 'feeds-tamper-efq-finder-wrapper',
    ),
    '#required' => TRUE,
  );
  if (!$entity_type) {
    return $form;
  }

  // Gather bundle information.
  $entity_info = entity_get_info($entity_type);
  $bundles = array();
  foreach ($entity_info['bundles'] as $machine_name => $info) {
    $bundles[$machine_name] = check_plain($info['label']);
  }
  $bundle = _feeds_tamper_efq_finder_get_value('bundle', $form_state, $settings);
  $bundle = isset($bundles[$bundle]) ? $bundle : NULL;
  $form['bundle'] = array(
    '#type' => 'select',
    '#title' => t('Bundle'),
    '#options' => $bundles,
    '#default_value' => $bundle,
    '#ajax' => array(
      'callback' => 'feeds_tamper_efq_finder_ajax',
      'wrapper' => 'feeds-tamper-efq-finder-wrapper',
    ),
    '#empty_option' => t('-- Select --'),
  );

  // Gather field definitions.
  $fields = array();
  foreach ($entity_info['schema_fields_sql']['base table'] as $property) {
    $fields[$property] = $property;
  }
  if ($bundle) {
    foreach (field_info_instances($entity_type, $bundle) as $machine_name => $info) {
      $fields[$machine_name] = check_plain($info['label']);
    }
  }
  else {
    foreach (field_info_instances($entity_type) as $bundle_instances) {
      foreach ($bundle_instances as $machine_name => $info) {
        $fields[$machine_name] = check_plain($info['label']);
      }
    }
  }
  $field = _feeds_tamper_efq_finder_get_value('field', $form_state, $settings);
  $field = isset($fields[$field]) ? $field : NULL;
  $form['field'] = array(
    '#type' => 'select',
    '#title' => t('Field'),
    '#options' => $fields,
    '#default_value' => $field,
    '#ajax' => array(
      'callback' => 'feeds_tamper_efq_finder_ajax',
      'wrapper' => 'feeds-tamper-efq-finder-wrapper',
    ),
    '#required' => TRUE,
  );
  if (!$field || in_array($field, $entity_info['schema_fields_sql']['base table'])) {
    return $form;
  }
  $field_info = field_info_field($field);
  $columns = array();
  foreach (array_keys($field_info['columns']) as $column) {
    $columns[$column] = $column;
  }
  $column = _feeds_tamper_efq_finder_get_value('column', $form_state, $settings);
  $column = isset($columns[$column]) ? $column : key($columns);
  $form['column'] = array(
    '#type' => 'select',
    '#title' => t('Column'),
    '#options' => $columns,
    '#default_value' => $column,
    '#required' => TRUE,
  );
  return $form;
}