Index: plugins/FeedsNodeProcessor.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feeds/plugins/FeedsNodeProcessor.inc,v retrieving revision 1.34 diff -u -p -r1.34 FeedsNodeProcessor.inc --- plugins/FeedsNodeProcessor.inc 16 May 2010 21:24:50 -0000 1.34 +++ plugins/FeedsNodeProcessor.inc 17 Jun 2010 22:56:07 -0000 @@ -21,6 +21,14 @@ class FeedsNodeProcessor extends FeedsPr // Keep track of processed items in this pass. $processed = 0; + + //Set the default user to be assigned as author of nodes. + $assigned_user_id = 0; + + //Check if Feed Importer is standalone and assign user based on form setting. + if (feeds_importer($this->id)->config['content_type'] == '') { + $assigned_user_id = $this->config['explicit_author']; + } while ($item = $batch->shiftItem()) { @@ -60,7 +68,8 @@ class FeedsNodeProcessor extends FeedsPr // Populate properties that are set by node_object_prepare(). $node->log = 'Created/updated by FeedsNodeProcessor'; - $node->uid = 0; + $node->uid = $assigned_user_id; + // Map and save nodes. If errors occur don't stop but report them. try { @@ -172,6 +181,7 @@ class FeedsNodeProcessor extends FeedsPr 'update_existing' => 0, 'expire' => FEEDS_EXPIRE_NEVER, 'mappings' => array(), + 'explicit_author' => 0, ); } @@ -202,10 +212,40 @@ class FeedsNodeProcessor extends FeedsPr '#description' => t('Check if existing items should be updated from the feed.'), '#default_value' => $this->config['update_existing'], ); + + //If Feed Importer is not attached to a content type we give user the chance to assign author. + if (feeds_importer($this->id)->config['content_type'] == '') { + $form['node_author'] = array( + '#type' => 'fieldset', + '#title' => t('Feed Results Author'), + ); + + //Retrieve the explicit author's name from the stored uid to make it easier for user. + $explicit_author = user_load(array('uid' => $this->config['explicit_author'])); + $explicit_author_name = (empty($explicit_author->name)) ? 'anonymous' : $explicit_author->name; + + $form['node_author']['explicit_author'] = array( + '#type' => 'textfield', + '#title' => t('Author for created nodes'), + '#description' => t('Explicitly set the user that will be set as author of nodes - leave it empty to assign to "anonymous".'), + '#autocomplete_path' => 'user/autocomplete', + '#default_value' => $explicit_author_name, + ); + } + return $form; } /** + * Override parent::configFormValidate(). + */ + public function configFormValidate(&$values) { + //Store the user $uid based on the user name supplied through the form. + $explicit_author = user_load(array('name' => $values['explicit_author'])); + $values['explicit_author'] = $explicit_author->uid; + } + + /** * Override setTargetElement to operate on a target item that is a node. */ public function setTargetElement($target_node, $target_element, $value) {