You are here

public function FeedsQueryPathParser::sourceForm in Feeds QueryPath Parser 6

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

Source form.

Overrides FeedsPlugin::sourceForm

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

File

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

Class

FeedsQueryPathParser
@file

Code

public function sourceForm($source_config) {
  $form = array();
  $form['#weight'] = -10;
  $form['#tree'] = TRUE;
  $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'];
      }
    }
  }
  if (empty($mappings)) {
    $form['error_message']['#value'] = 'FeedsQueryPathParser: No mappings were defined.';
    return $form;
  }
  $form['context'] = array(
    '#type' => 'textfield',
    '#title' => t('Context'),
    '#required' => TRUE,
    '#description' => t('This is the base query, all other queries will run in this context.'),
    '#default_value' => isset($source_config['context']) ? $source_config['context'] : '',
    '#maxlength' => 1024,
  );
  $form['sources'] = array(
    '#type' => 'fieldset',
  );
  $form['attrs'] = array(
    '#title' => t('Attributes'),
    '#type' => 'fieldset',
    '#description' => t('If you want an attribute returned for a field, type its name here.'),
  );
  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['sources']['help']['#value'] = '<div class="help">' . theme('item_list', $items) . '</div>';
  }
  $variables = array();
  foreach ($mappings as $source => $target) {
    $form['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['sources'][$source]['#description'] .= '<br>' . t('The variables ' . implode(', ', $variables) . ' are availliable for replacement.');
    }
    $variables[] = '$' . $target;
    $form['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['rawXML'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Select the queries you would like to return raw XML or HTML'),
    '#options' => $mappings,
    '#default_value' => isset($source_config['rawXML']) ? $source_config['rawXML'] : array(),
  );
  $form['options'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => 'QueryPath Parser Options',
  );

  //$form['options']['errors'] = array(

  //  '#type' => 'checkbox',
  //  '#title' => t('Show error messages.'),
  //  '#default_value' => isset($source_config['options']['errors']) ? $source_config['options']['errors'] : FALSE,

  //);

  //if (extension_loaded('tidy')) {

  //  $form['options']['tidy'] = array(
  //    '#type'          => 'checkbox',
  //    '#title'         => t('Use Tidy'),
  //    '#description'   => t('The Tidy PHP extension has been detected.
  //                          Select this to clean the markup before parsing.'),
  //    '#default_value' => isset($source_config['options']['tidy']) ? $source_config['options']['tidy'] : FALSE,
  //  );

  //}
  $form['options']['debug'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Debug Query'),
    '#options' => array_merge(array(
      'context' => 'context',
    ), $mappings),
    '#default_value' => isset($source_config['options']['debug']) ? $source_config['options']['debug'] : array(),
  );
  return $form;
}