public function FeedsJSONPathParser::sourceForm in Feeds JSONPath Parser 6
Same name and namespace in other branches
- 7 FeedsJSONPathParser.inc \FeedsJSONPathParser::sourceForm()
Source form.
Overrides FeedsPlugin::sourceForm
1 call to FeedsJSONPathParser::sourceForm()
- FeedsJSONPathParser::configForm in ./
FeedsJSONPathParser.inc - Override parent::configForm().
File
- ./
FeedsJSONPathParser.inc, line 127 - Provides the Class for Feeds JSONPath Parser.
Class
- FeedsJSONPathParser
- Base class for the HTML and XML parsers.
Code
public function sourceForm($source_config) {
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'], 'jsonpath_parser:') === 0) {
$mappings[$mapping['source']] = $mapping['target'];
if ($mapping['unique']) {
$uniques[] = $mapping['target'];
}
}
}
$form = array();
$form['jsonpath'] = array(
'#type' => 'fieldset',
'#title' => t('JSONPath Parser Settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);
if (empty($mappings)) {
$form['jsonpath']['error_message']['#value'] = '<div class="help">' . t('FeedsJSONPathParser: No mappings were defined.') . '</div>';
return $form;
}
$form['jsonpath']['context'] = array(
'#type' => 'textfield',
'#title' => t('Context'),
'#required' => TRUE,
'#description' => t('This is the base query, all other queries will execute in this context.'),
'#default_value' => isset($source_config['context']) ? $source_config['context'] : '',
'#maxlength' => 1024,
'#size' => 80,
);
$form['jsonpath']['sources'] = array(
'#type' => 'fieldset',
);
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['jsonpath']['sources']['help']['#value'] = '<div class="help">' . theme('item_list', array(
'items' => $items,
)) . '</div>';
}
$variables = array();
foreach ($mappings as $source => $target) {
$form['jsonpath']['sources'][$source] = array(
'#type' => 'textfield',
'#title' => $target,
'#description' => t('The JSONPath expression to execute.'),
'#default_value' => isset($source_config['sources'][$source]) ? $source_config['sources'][$source] : '',
'#maxlength' => 1024,
'#size' => 80,
);
if (!empty($variables)) {
$form['jsonpath']['sources'][$source]['#description'] .= '<br>' . t('The variables ' . implode(', ', $variables) . ' are availliable for replacement.');
}
$variables[] = '{' . $target . '}';
}
$form['jsonpath']['debug'] = array(
'#type' => 'fieldset',
'#title' => t('Debug'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['jsonpath']['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;
}