You are here

function feeds_ui_mapping_form in Feeds 8.2

Same name and namespace in other branches
  1. 6 feeds_ui/feeds_ui.admin.inc \feeds_ui_mapping_form()
  2. 7.2 feeds_ui/feeds_ui.admin.inc \feeds_ui_mapping_form()
  3. 7 feeds_ui/feeds_ui.admin.inc \feeds_ui_mapping_form()

Edit mapping.

@todo Completely merge this into config form handling. This is just a shared form of configuration, most of the common functionality can live in FeedsProcessor, a flag can tell whether mapping is supported or not.

1 string reference to 'feeds_ui_mapping_form'
feeds_ui_edit_page in feeds_ui/feeds_ui.admin.inc
Edit feed configuration.

File

feeds_ui/feeds_ui.admin.inc, line 453
Contains all page callbacks, forms and theming functions for Feeds administrative pages.

Code

function feeds_ui_mapping_form($form, &$form_state, $importer) {
  $form['#importer'] = $importer->id;
  $form['#mappings'] = $mappings = $importer->processor
    ->getMappings();
  $form['help']['#markup'] = feeds_ui_mapping_help();
  $form['#prefix'] = '<div id="feeds-ui-mapping-form-wrapper">';
  $form['#suffix'] = '</div>';

  // Get mapping sources from parsers and targets from processor, format them
  // for output.
  // Some parsers do not define mapping sources but let them define on the fly.
  if ($sources = $importer->parser
    ->getMappingSources()) {
    $source_options = _feeds_ui_format_options($sources);
    foreach ($sources as $k => $source) {
      $legend['sources'][$k]['name']['#markup'] = empty($source['name']) ? $k : $source['name'];
      $legend['sources'][$k]['description']['#markup'] = empty($source['description']) ? '' : $source['description'];
    }
  }
  else {
    $legend['sources']['#markup'] = t('This parser supports free source definitions. Enter the name of the source field in lower case into the Source text field above.');
  }
  $targets = $importer->processor
    ->getMappingTargets();
  $target_options = _feeds_ui_format_options($targets);
  $legend['targets'] = array();
  foreach ($targets as $k => $target) {
    $legend['targets'][$k]['name']['#markup'] = empty($target['name']) ? $k : $target['name'];
    $legend['targets'][$k]['description']['#markup'] = empty($target['description']) ? '' : $target['description'];
  }

  // Legend explaining source and target elements.
  $form['legendset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Legend'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $form['legendset']['legend'] = $legend;

  // Add config forms and remove flags to mappings.
  $form['config'] = $form['remove_flags'] = $form['mapping_weight'] = array(
    '#tree' => TRUE,
  );
  if (is_array($mappings)) {
    $delta = count($mappings) + 2;
    foreach ($mappings as $i => $mapping) {
      if (isset($targets[$mapping['target']])) {
        $form['config'][$i] = feeds_ui_mapping_settings_form($form, $form_state, $i, $mapping, $targets[$mapping['target']]);
      }
      $form['remove_flags'][$i] = array(
        '#type' => 'checkbox',
        '#title' => t('Remove'),
        '#prefix' => '<div class="feeds-ui-checkbox-link">',
        '#suffix' => '</div>',
      );
      $form['mapping_weight'][$i] = array(
        '#type' => 'weight',
        '#title' => '',
        '#default_value' => $i,
        '#delta' => $delta,
        '#attributes' => array(
          'class' => array(
            'feeds-ui-mapping-weight',
          ),
        ),
      );
    }
  }
  if (isset($source_options)) {
    $form['source'] = array(
      '#type' => 'select',
      '#title' => t('Source'),
      '#title_display' => 'invisible',
      '#options' => $source_options,
      '#empty_option' => t('- Select a source -'),
      '#description' => t('An element from the feed.'),
    );
  }
  else {
    $form['source'] = array(
      '#type' => 'textfield',
      '#title' => t('Source'),
      '#title_display' => 'invisible',
      '#size' => 20,
      '#default_value' => '',
      '#description' => t('The name of source field.'),
    );
  }
  $form['target'] = array(
    '#type' => 'select',
    '#title' => t('Target'),
    '#title_display' => 'invisible',
    '#options' => $target_options,
    '#empty_option' => t('- Select a target -'),
    '#description' => t('The field that stores the data.'),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}