3

I have created a feed importer. I do not know how to set the author of the feed item to name of the original author of the feed? Is there any method to do it? Or will apply any patch? Any patch for this functionality will be welcome.

3

I had a hard time getting this to work.


My current settings work.

Feed Importer
-attached to Feed (content type)
-RSS parser
-Mapping: Description to Description, Title to Title, Item GUID to GUID (Unique), Item URL to URL (Unique), Published Date to Published Date, and Feed Node: User ID to User ID. It is important to have a unique identifier or you get duplicate imports.

The Feed Itself
-Set "Authored By" to a Drupal user on your site. This lets you custom the user. Create a new user if necessary. I created a couple dummy users just to get their names to appear as feed item authors.

3

Here is the up to date code. Put this code into a custom module to achieve the desired result:

<?php

/**
 * Implement hook_feeds_preserve
 */
function MODULE_NAME_feeds_presave(FeedsSource $source, $entity, $item) {
  if ($entity->type == 'WRITE_NODE_MACHINE_NAME_HERE') {
    global $user;
    $entity->uid = $user->uid;
  }
}

?>
  • node_machine_name is feed node to which import is attached or node that are being imported? – kiranking Oct 21 '15 at 9:33
1

The Feeds module keeps track of the feed that was used to import each node. All you need is a nodeapi('presave') implementation that will pass the feed's author on to the node being imported.

A snippet like this should do it:

function YOUR_MODULE_nodeapi(&$node, $op, $a3, $a4) {
  if ($op == 'presave' && !empty($node->feed_node_item)) {
    $feed_node = node_load($node->feed_node_item->feed_nid);
    $node->uid = $feed_node->uid;
  }
}
1

Aaron Kreider gave the right answer. Put it in short, in mapping, set the source "feed node: user id", set the target "user id"; and the node author will be defined as the feed author.

It took me a while to find out this and fulfilled my work. Some people mentioned that you need to do coding, I guess they are talking about previous versions, or perhaps they didn't notice the easy solution.

1

Importing a CSV file and setting the Author / Authoring field for the node based on a header / column from the CSV file.

Using Drupal 7 with feeds-7.x-2.0-alpha8

  1. In my CSV file I have a column with the heading Author.
  2. I added a new user with permissions to edit the appropriate content. The user's name came from the Author column in my CSV file. (You must add the user to Drupal before importing the CSV file.)
  3. In: Home » Administration » Structure » Feeds » Foo, I set the source field to Author and the target field to Username. (Foo is the name of the custom importer which I created.)
  4. I imported the CSV file.
  5. Success!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.