public function FeedsExBase::configFormValidate in Feeds extensible parsers 7
Same name and namespace in other branches
- 7.2 src/FeedsExBase.inc \FeedsExBase::configFormValidate()
2 calls to FeedsExBase::configFormValidate()
1 method overrides FeedsExBase::configFormValidate()
File
- src/
FeedsExBase.inc, line 581 - Contains FeedsExBase.
Class
- FeedsExBase
- The Feeds extensible parser.
Code
public function configFormValidate(&$values) {
// Throwing an exception during validation shows a nasty error to users.
try {
$this
->loadLibrary();
} catch (RuntimeException $e) {
$this
->getMessenger()
->setMessage($e
->getMessage(), 'error', FALSE);
return;
}
// @todo We should do this in Feeds automatically.
$values += $this
->configDefaults();
// Remove sources.
foreach ($values['sources'] as $machine_name => $source) {
if (!empty($source['remove'])) {
unset($values['sources'][$machine_name]);
}
}
// Validate context.
if ($this
->hasConfigurableContext()) {
if ($message = $this
->validateExpression($values['context']['value'])) {
form_set_error('context', $message);
}
}
// Validate expressions.
foreach (array_keys($values['sources']) as $machine_name) {
if ($message = $this
->validateExpression($values['sources'][$machine_name]['value'])) {
form_set_error('sources][' . $machine_name . '][value', $message);
}
}
// Add new source.
if (strlen($values['add']['machine_name']) && strlen($values['add']['name'])) {
if ($message = $this
->validateExpression($values['add']['value'])) {
form_set_error('add][value', $message);
}
else {
$values['sources'][$values['add']['machine_name']] = $values['add'];
}
}
// Rebuild sources to keep the configuration values clean.
$columns = $this
->getFormHeader();
unset($columns['remove'], $columns['machine_name']);
$columns = array_keys($columns);
foreach ($values['sources'] as $machine_name => $source) {
$new_value = array();
foreach ($columns as $column) {
$new_value[$column] = $source[$column];
}
$values['sources'][$machine_name] = $new_value;
}
// Sort by weight.
uasort($values['sources'], 'ctools_plugin_sort');
// Let the encoder do its thing.
$this
->getEncoder()
->configFormValidate($values);
}