You are here

function feeds_querypath_parser_form_feeds_ui_mapping_form_alter in Feeds QueryPath Parser 6

Same name and namespace in other branches
  1. 7 FeedsQueryPathParser.inc \feeds_querypath_parser_form_feeds_ui_mapping_form_alter()

Implementation of hook_form_feeds_ui_mapping_form_alter().

This is an interesting bit of work. Each source name has to be unique, but we have no idea how many to create with getMappingSources() because we don't know how many targets there are going to be.

Solution is to keep track in the form how many have been added.

File

./FeedsQueryPathParser.inc, line 302
Provides the class for FeedsQueryPathParser.

Code

function feeds_querypath_parser_form_feeds_ui_mapping_form_alter(&$form, &$form_state) {
  $newest_querypath_mapping = array();
  foreach ($form['#mappings'] as $mapping) {
    if (strpos($mapping['source'], 'querypathparser:') === 0) {
      $newest_querypath_mapping = $mapping;
    }
  }
  if (!empty($newest_querypath_mapping)) {
    list($a, $count) = explode(':', $newest_querypath_mapping['source']);
    $default_source = $a . ':' . '0';
    $label = $form['source']['#options'][$default_source];
    unset($form['source']['#options'][$default_source]);
    $form['source']['#options'][$a . ':' . ++$count] = $label;
  }
}