function feeds_ui_importer_import_validate in Feeds 7.2
Form validation handler for feeds_ui_importer_import().
See also
feeds_ui_importer_import_submit()
File
- feeds_ui/
feeds_ui.admin.inc, line 1178 - Contains all page callbacks, forms and theming functions for Feeds administrative pages.
Code
function feeds_ui_importer_import_validate($form, &$form_state) {
$form_state['values']['importer'] = trim($form_state['values']['importer']);
$form_state['values']['id'] = trim($form_state['values']['id']);
if (!empty($form_state['values']['id']) && preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['id'])) {
form_error($form['id'], t('Feeds importer id must be alphanumeric with underscores only.'));
}
if (substr($form_state['values']['importer'], 0, 5) == '<?php') {
$form_state['values']['importer'] = substr($form_state['values']['importer'], 5);
}
$feeds_importer = NULL;
ob_start();
eval($form_state['values']['importer']);
ob_end_clean();
if (!is_object($feeds_importer)) {
return form_error($form['importer'], t('Unable to interpret Feeds importer code.'));
}
if (empty($feeds_importer->api_version) || $feeds_importer->api_version < 1) {
form_error($form['importer'], t('The importer is not compatible with this version of Feeds.'));
}
elseif (version_compare($feeds_importer->api_version, feeds_api_version(), '>')) {
form_error($form['importer'], t('That importer is created for the version %import_version of Feeds, but you only have version %api_version.', array(
'%import_version' => $feeds_importer->api_version,
'%api_version' => feeds_api_version(),
)));
}
// Change to user-supplied id.
if ($form_state['values']['id']) {
$feeds_importer->id = $form_state['values']['id'];
}
$exists = feeds_ui_importer_machine_name_exists($feeds_importer->id);
if ($exists && !$form_state['values']['id_override']) {
return form_error($form['id'], t('Feeds importer already exists with that id.'));
}
if (!$form_state['values']['bypass_validation']) {
$errors = array();
$importer = feeds_importer($feeds_importer->id);
$importer
->setConfig($feeds_importer->config);
foreach (array(
'fetcher',
'parser',
'processor',
) as $type) {
$plugin = feeds_plugin($feeds_importer->config[$type]['plugin_key'], $feeds_importer->id);
if (!$plugin instanceof FeedsMissingPlugin) {
$importer
->setPlugin($feeds_importer->config[$type]['plugin_key']);
$importer->{$type}
->setConfig($feeds_importer->config[$type]['config']);
}
}
$errors = array_merge($errors, $importer
->validateConfig());
if (!empty($errors)) {
form_error($form['importer'], theme('item_list', array(
'items' => $errors,
)));
}
}
$form_state['importer'] = $feeds_importer;
}