Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I am using a standalone form (Attach to content type: Use standalone form) to import nodes.
And I need to programmatically change the URL submitted when import form (/import/my_feed) is submitted.
How can I do this? I do not find this into "The developer's guide to Feeds".
Thanks for your reply.
Best regards,
Michel.
Comments
Comment #1
twistor CreditAttribution: twistor commentedAre you trying to change the form value when the form gets submitted?
If so, then just use a form alter.
Comment #2
michel.settembrino CreditAttribution: michel.settembrino commentedHi Twistor,
Thanks for your quick reply.
No, I'm not trying to change the form value when the form gets submitted.
Sometimes the URL must be programmatically and definitevely changed. So by the next CRON run, the new URL is used.
Let's take an example.
Is that now clear enough?
Comment #3
twistor CreditAttribution: twistor commentedI'm still not quite sure I follow, but you can get/set the feed source URL programmically like so:
Comment #4
michel.settembrino CreditAttribution: michel.settembrino commentedThanks Twistor. This is exactly what I want!
It tooks me sometimes to understand that I had to replace 'importer_id' by the id of my importer but then it works.
I would suggest to add this info into "The developer's guide to Feeds".
Best regards,
Michel.
Comment #6
Cromian CreditAttribution: Cromian commentedSorry for being naive ... what hook do we use to implement the following code?
Comment #7
MegaChriz CreditAttribution: MegaChriz commented@Cromian
That depends on when you want the feeds source URL to be changed.
If you want the URL to be changed just before an import starts, implement the hook
hook_feeds_before_import()
:If you want the URL to be changed when someone submits the import form, use a form alter hook instead. In there, add a submit handler. In the form submit handler function, perform the needed changes.
Comment #8
Cromian CreditAttribution: Cromian commentedThanks!
Comment #9
kopeboy CreditAttribution: kopeboy commentedHow to compose the source URL from a field of the Feed, or a field of a referenced entity?
Example:
"Website" Taxonomy term:
- Name = website1
- field_api_base_url = "https://api.website1.com/api"
- field_api_key = "abcd"
- field_account = "user1"
Feed:
- field_website (Entity Reference) = "website1"
- field_api_module (List) = "account"
=> Source URL = [field_website:field_api_base_url]?[field_api_module]=[field_website:field_account]&api_key=[field_website:field_account]
= "https://api.website1.com/api?module=account&account=user1&api_key=abcd"
🙏🏻
Comment #10
kopeboy CreditAttribution: kopeboy commentedSorry my bad, I noticed the Drupal 7 version Feed importers are not fieldable entities.
I created this issue for 8.x version here: https://www.drupal.org/project/feeds/issues/3282260
Comment #11
kopeboy CreditAttribution: kopeboy commented