function feeds_node_validate in Feeds 7
Same name and namespace in other branches
- 8.2 feeds.module \feeds_node_validate()
- 7.2 feeds.module \feeds_node_validate()
Implements hook_node_validate().
Related topics
File
- ./
feeds.module, line 335 - Feeds - basic API functions and hook implementations.
Code
function feeds_node_validate($node, $form, &$form_state) {
if (!($importer_id = feeds_get_importer_id($node->type))) {
return;
}
// Keep a copy of the title for subsequent node creation stages.
// @todo: revisit whether $node still looses all of its properties
// between validate and insert stage.
$last_title =& drupal_static('feeds_node_last_title');
$last_feeds =& drupal_static('feeds_node_last_feeds');
// On validation stage we are working with a FeedsSource object that is
// not tied to a nid - when creating a new node there is no
// $node->nid at this stage.
$source = feeds_source($importer_id);
// Node module magically moved $form['feeds'] to $node->feeds :P.
// configFormValidate may modify $last_feed, smuggle it to update/insert stage
// through a static variable.
$last_feeds = $node->feeds;
$source
->configFormValidate($last_feeds);
// If node title is empty, try to retrieve title from feed.
if (trim($node->title) == '') {
try {
$source
->addConfig($last_feeds);
if (!($last_title = $source
->preview()
->getTitle())) {
throw new Exception();
}
} catch (Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
form_set_error('title', t('Could not retrieve title from feed.'), 'error');
}
}
}