Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The attached patch adds a hook hook_feeds_before_import()
as discussed, such that a rules integration could use it to customize the imported entities before saving + to skip saving.
Based on the hook we could add an event for it + an action for skipping the import. The entity could be manipulated with the usual rules actions else too. :)
Comment | File | Size | Author |
---|---|---|---|
#14 | feeds_rules_integration_14.patch | 4.87 KB | dasjo |
#11 | feeds_rules_integration.patch | 4.94 KB | fago |
#10 | feeds_rules_11.patch | 4.22 KB | dasjo |
#8 | feeds_rules_10.patch | 4.45 KB | dasjo |
#7 | feeds_rules_9.patch | 4.47 KB | dasjo |
Comments
Comment #1
alex_b CreditAttribution: alex_b commentedLooking good.
I think we should change the hook signature from
to:
Reasons:
- more consistent with hook_feeds_after_import() which is called on an import level. A theoretical hook_feeds_pre_import() would have to be invoked on an import level, too.
- usage of $source is consistent with most other hooks (see feeds.api.php) [edit: processor can be accessed via feeds_importer($source->id)->processor]
- $entity_type is accessible on $entity->feeds_item->entity_type
Comment #2
fagook, I've updated the patch accordingly. I named the hook hook_feeds_presave() though to be consistent with hook_entity_presave().
Comment #3
fagofixed it.
Comment #4
dasjoadditions:
this is handy for skipping items, but of course feeds will try to import them again.
we decided to also implement a FeedsEntityProcessor in order to import generic entities and a more specific FeedsMessageProcessor in order to save them as messages using the message module http://drupal.org/project/message
Comment #5
fagoUnnecessary empty line:
Else the patch looks good to me.
Comment #6
fago@entity-processor: see #1033202: [Meta] Generic entity processor
Comment #7
dasjoremove unnecessary empty line
Comment #8
dasjosorry, my patch was in the wrong format
Comment #9
fagothe last patch still has the line? ;)
Comment #10
dasjoremoved entityType from configDefaults as this caused endless recusion in some cases
also the empty line should be gone now :)
Comment #11
fagoI took the patch form #10 and added some improvements:
* add the node-type as a bundle to the variable in case of the node processor -> saves you from checking it in rules
* added some more comments and help for the skip action
* fixed the provided variable to skip-saving in rules, so it isn't double-saved
Patch works fine for me.
It would be cleaner if the processor would tell us what the configured bundle is, as this would work for other processors too. I'm not sure though whether it is ok to introduce something like FeedsProcessor::getBundle() in feeds current development state?
Anyway, currently the only entity-type feed supports that has bundles is "node".
Comment #12
fagoimproved title
Comment #13
dasjojust tested, works nicely :)
---
usage:
- create a reaction event rule on "Before saving an item imported via YourFeedsImporter".
- within the rule or any sub-component use the action "Skip import of feeds item" in order to flag the imported item as skipped.
Comment #14
dasjominor re-roll of fago's patch in #11 which adds a check:
this prevents error messages when using the action for non-feeds-imported items
Comment #15
febbraro CreditAttribution: febbraro commentedCommitted to 7.x thanks.
http://drupalcode.org/project/feeds.git/commit/b2b2a94
Comment #17
colanThanks. This just hosed the work I was doing over at #1362378: Provide entity post-save hook. ;) I wish I found this earlier, but I suppose that's what happens when the issue queue gets so huge.
It's not necessarily a duplicate, because we still need the post-save hook. The issue is that the signatures are different. I've got:
...and this one does:
However, from the note above, I'm assuming that the processor is still accessible?
So if that's the case, we can leave this as is, and just make the other issue about post-saving.
Comment #18
OldAccount CreditAttribution: OldAccount commentedMarked #1344028: Use Rules to trigger feed importer as duplicate of this issue.