You are here

public function FeedsQueryPathParser::sourceForm in Feeds QueryPath Parser 7

Same name and namespace in other branches
  1. 6 FeedsQueryPathParser.inc \FeedsQueryPathParser::sourceForm()

Source form.

1 call to FeedsQueryPathParser::sourceForm()
FeedsQueryPathParser::configForm in ./FeedsQueryPathParser.inc
Override parent::configForm().

File

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

Class

FeedsQueryPathParser
@file

Code

public function sourceForm($source_config) {
  $form = array();

  // Allow for config inheritance.
  if (empty($source_config)) {
    $source_config = $this->config;
  }
  $mappings_ = feeds_importer($this->id)->processor->config['mappings'];
  $uniques = $mappings = array();
  foreach ($mappings_ as $mapping) {
    if (strpos($mapping['source'], 'querypathparser:') === 0) {
      $mappings[$mapping['source']] = $mapping['target'];
      if ($mapping['unique']) {
        $uniques[] = $mapping['target'];
      }
    }
  }
  $form['querypath'] = array(
    '#type' => 'fieldset',
    '#title' => t('QueryPath Parser Settings'),
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (empty($mappings)) {
    $form['querypath']['error_message']['#markup'] = '<div class="help">' . t('FeedsQueryPathParser: No mappings were defined. Define mappings !link.', array(
      '!link' => l('here', 'admin/structure/feeds/' . $this->id . '/mapping'),
    )) . '</div>';
    return $form;
  }
  $form['querypath']['context'] = array(
    '#type' => 'textfield',
    '#title' => t('Context'),
    '#required' => TRUE,
    '#description' => t('The element that represents the beginning of a new item, like h1 or body. If you identify a context that occurs more than once in a feed, a new node or item will be created each time it is encountered.'),
    '#default_value' => isset($source_config['context']) ? $source_config['context'] : '',
    '#maxlength' => 1024,
  );
  $form['querypath']['sources'] = array(
    '#title' => t('Selectors'),
    '#type' => 'fieldset',
    '#description' => t('Indicate the CSS selector that marks where each field is located within the context, like div#content or h2:first.'),
  );
  $form['querypath']['attrs'] = array(
    '#title' => t('Attributes'),
    '#type' => 'fieldset',
    '#description' => t('Identify the attribute value to use for a field, if desired, like src or title. The element text will be used if no attribute is identified.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  if (!empty($uniques)) {
    $items = array(
      format_plural(count($uniques), t('Field <strong>!column</strong> is mandatory and considered unique: only one item per !column value will be created.', array(
        '!column' => implode(', ', $uniques),
      )), t('Fields <strong>!columns</strong> are mandatory and values in these columns are considered unique: only one entry per value in one of these columns will be created.', array(
        '!columns' => implode(', ', $uniques),
      ))),
    );
    $form['querypath']['sources']['help']['#markup'] = '<div class="help">' . theme('item_list', array(
      'items' => $items,
    )) . '</div>';
  }
  $variables = array();
  foreach ($mappings as $source => $target) {
    $form['querypath']['sources'][$source] = array(
      '#type' => 'textfield',
      '#title' => $target,
      '#description' => t('The CSS selector for this field.'),
      '#default_value' => isset($source_config['sources'][$source]) ? $source_config['sources'][$source] : '',
      '#maxlength' => 1024,
    );
    if (!empty($variables)) {
      $form['querypath']['sources'][$source]['#description'] .= '<br>' . t('The variables ' . implode(', ', $variables) . ' are available for replacement.');
    }
    $variables[] = '{' . $target . '}';
    $form['querypath']['attrs'][$source] = array(
      '#type' => 'textfield',
      '#title' => $target,
      '#description' => t('The attribute to return.'),
      '#default_value' => isset($source_config['attrs'][$source]) ? $source_config['attrs'][$source] : '',
      '#maxlength' => 1024,
    );
  }
  $form['querypath']['rawXML'] = array(
    '#type' => 'checkboxes',
    '#options' => $mappings,
    '#default_value' => isset($source_config['rawXML']) ? $source_config['rawXML'] : array(),
  );
  $form['querypath']['debug'] = array(
    '#type' => 'fieldset',
    '#title' => t('Debug'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['querypath']['debug']['options'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Debug query'),
    '#options' => array_merge(array(
      'context' => 'context',
    ), $mappings),
    '#default_value' => isset($source_config['debug']['options']) ? $source_config['debug']['options'] : array(),
  );
  return $form;
}