Comments

ScorpionGhost created an issue. See original summary.

megachriz’s picture

Title: Add, please, Youtube support for the module Youtube » Feeds: add mapping target for 'youtube' field type
Project: Feeds » YouTube Field
Version: 8.x-3.x-dev » 8.x-1.x-dev

Targets for fields provided by a contrib module, should go in that contrib module, so moving this issue to the YouTube Field issue queue.

scorpionghost’s picture

Thanks

guschilds’s picture

Hi ScorpionGhost,

Support for feeds was added to the 7.x version of the module in #1789844: Support for Feeds and later ported to Drupal 8. You'll find youtube_feeds_processor_targets_alter() and youtube_set_target() in youtube.module. I didn't do the Drupal 8 port and don't know much about Drupal 8 & Feeds, but that's the place to look first. If you find that it works as needed, please close this issue. If it doesn't work, please try to provide a patch that does. Thanks!

megachriz’s picture

@guschilds
The hook hook_feeds_processor_targets_alter() (and other Feeds hooks) no longer exist in the D8 version of Feeds. I see that the methods youtube_feeds_processor_targets_alter() and youtube_set_target() are still present in the D8 version of this project, but that's basically dead redundant code now.

In the D8 version of Feeds, targets are plugins. You would need to create a FeedsTarget plugin for it. I've written some instructions for it in #2997019: Mapping for Ubercart Price and Attributes For Drupal 8 (still need to revise that and add it to the offical documentation).

guschilds’s picture

Title: Feeds: add mapping target for 'youtube' field type » Port D7 Feeds hook to a D8 target plugin

Interesting. Thanks MegaChriz! I'm not surprised that it's a plugin and not a hook these days. That documentation looks really helpful.

ScorpionGhost, If you're able to create a patch with the plugin, I'd be happy to review it. I can't make any promises regarding when I'll be able to try and do it myself.

marc.groth’s picture

Status: Active » Needs review
StatusFileSize
new827 bytes

@MegaChriz thank you so much for providing such detailed instructions on how to implement this. Thanks to you I was able to create a very simple feed importer for YouTube video data. The importer will allow you to set both the Video URL and Video ID.

It would be awesome if somebody else could test and verify the patch/functionality. You can do so as follows:

1. Add the patch to your composer.json (under extras > patches) e.g.:

"drupal/youtube": {
                "Feeds module support": "https://www.drupal.org/files/issues/2020-04-18/youtube-feed_target-3123371-9-d8.patch"
            }

2. Run 'composer install' which should remove/re-add the module with the patch applied.

3. Clear the cache

That's it! From there you should be able to map any 'YouTube Video' field. I have applied the attached patch to my project using composer and it works really well.

marc.groth’s picture

StatusFileSize
new838 bytes

Sorry the formatting on the last patch was messed up for some reason. I've re-attached the correctly formatted patch. Please review/test against this one.

marc.groth’s picture

StatusFileSize
new849 bytes

Ahh third time's the charm haha. Just found a few more formatting issues. Updated patch attached.

guschilds’s picture

Hi marc.groth,

Thanks for the patch! A couple of questions before I test it:

Thanks!

marc.groth’s picture

Hey @guschilds,

  • Perhaps I've misunderstood the purpose of this ticket. I thought it was to add Feeds support for the YouTube field (so that it can be used within Feeds). That is what plugin I provided. What this means is you can map your feed importer to the YouTube video field and it should update the data accordingly. In my case it is just a YouTube video URL in the CSV of data but technically you could add any text as it just adds the text as is
  • It's probably a good idea to do this; but I must admit I'm not sure when I'll find time myself. It should be easy enough for someone to re-roll the patch if they want to take a crack at it. Otherwise I'll see what I can do when I find time
guschilds’s picture

Hi marc.groth,

I don't think you've misunderstood. I was just asking for an example feed to test this functionality with and in the past I'd used a feed from YouTube. I haven't used Feeds in years, so I'd forgotten that it can also be as simple as a CSV file. I'll create one and try that when I get the chance. I can also re-roll the patch to remove the outdated functions if no one else beats me to it. Thanks again.

  • guschilds committed 3757386 on 8.x-1.x
    Issue #3123371 by guschilds, MegaChriz: Improved D8 Feeds DX, removed...
  • guschilds committed 5000139 on 8.x-1.x authored by marc.groth
    Issue #3123371 by marc.groth, guschilds, MegaChriz: Added a D8 Feeds...
guschilds’s picture

Status: Needs review » Fixed

Hi marc.groth,

I tested your patch. It worked and I committed it.

That said, it took me a while to realize that I had to map and provide both the URL and the ID in the feed. It seems like a feed would typically provide one or the other. For that reason, I added a prepareValue() method to the plugin that takes one and generates the other. I've committed that separately, as well as the removal of the deprecated D7 functions mentioned above.

Going to close this now. The committed code will be included in the next release.

Thanks for the patch! And thanks to MegaChriz for the assist!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.