You are here

function theme_feeds_ui_mapping_form in Feeds 7.2

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

Theme function for feeds_ui_mapping_form().

File

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

Code

function theme_feeds_ui_mapping_form($variables) {
  $form = $variables['form'];
  $targets = $form['#feeds_targets'];
  $targets = _feeds_ui_format_options($targets, TRUE);
  $sources = $form['#feeds_sources'];

  // Some parsers do not define source options.
  $sources = $sources ? _feeds_ui_format_options($sources, TRUE) : array();

  // Build the actual mapping table.
  $header = array(
    t('Source'),
    t('Target'),
    t('Target configuration'),
    ' ',
    t('Weight'),
  );
  $rows = array();
  if (is_array($form['#mappings'])) {
    foreach ($form['#mappings'] as $i => $mapping) {
      $source = isset($sources[$mapping['source']]) ? check_plain($sources[$mapping['source']]) : check_plain($mapping['source']);
      $target = isset($targets[$mapping['target']]) ? check_plain($targets[$mapping['target']]) : '<em>' . t('Missing') . '</em>';

      // Add indicator to target if target configuration changed.
      if (isset($form['#mapping_settings'][$i])) {
        $target .= '<span class="warning">*</span>';
      }
      $rows[] = array(
        'data' => array(
          $source,
          $target,
          drupal_render($form['config'][$i]),
          drupal_render($form['remove_flags'][$i]),
          drupal_render($form['mapping_weight'][$i]),
        ),
        'class' => array(
          'draggable',
          'tabledrag-leaf',
        ),
      );
    }
  }
  if (!count($rows)) {
    $rows[] = array(
      array(
        'colspan' => 5,
        'data' => t('No mappings defined.'),
      ),
    );
  }
  $rows[] = array(
    drupal_render($form['source']),
    drupal_render($form['target']),
    '',
    drupal_render($form['add']),
    '',
  );
  $output = '';
  if (!empty($form['changed'])) {

    // This form element is only available if target configuration changed.
    $output .= drupal_render($form['changed']);
  }
  $output .= '<div class="help feeds-admin-ui">' . drupal_render($form['help']) . '</div>';
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'feeds-ui-mapping-overview',
    ),
  ));

  // Build the help table that explains available sources.
  $legend = '';
  $rows = array();
  foreach (element_children($form['legendset']['legend']['sources']) as $k) {
    $rows[] = array(
      check_plain(drupal_render($form['legendset']['legend']['sources'][$k]['name'])),
      check_plain(drupal_render($form['legendset']['legend']['sources'][$k]['description'])),
    );
  }
  if (count($rows)) {
    $legend .= '<h4>' . t('Sources') . '</h4>';
    $legend .= theme('table', array(
      'header' => array(
        t('Name'),
        t('Description'),
      ),
      'rows' => $rows,
    ));
  }

  // Build the help table that explains available targets.
  $rows = array();
  foreach (element_children($form['legendset']['legend']['targets']) as $k) {
    $rows[] = array(
      check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['name']) . ' (' . $k . ')'),
      check_plain(drupal_render($form['legendset']['legend']['targets'][$k]['description'])),
    );
  }
  $legend .= '<h4>' . t('Targets') . '</h4>';
  $legend .= theme('table', array(
    'header' => array(
      t('Name'),
      t('Description'),
    ),
    'rows' => $rows,
  ));

  // Stick tables into collapsible fieldset.
  $form['legendset']['legend'] = array(
    '#markup' => '<div>' . $legend . '</div>',
  );
  $output .= drupal_render($form['legendset']);
  $output .= drupal_render_children($form);
  drupal_add_tabledrag('feeds-ui-mapping-overview', 'order', 'sibling', 'feeds-ui-mapping-weight');
  return $output;
}