Would be nice to have a live preview of the youtube player, for the user to know if his link works. Any hint where to start implementing that? Another option would be to do that using a live preview module...

Comments

geraldito created an issue. See original summary.

guschilds’s picture

Status: Active » Postponed (maintainer needs more info)

Hey geraldito,

I don't know that this isn't common functionality for field types. I'm also not sure what you're referring to when you say "Another option would be to do that using a live preview module...". Could you provide more information there? There might be a contrib module that makes this easier, but I don't know of any. Users can always test the correctness of their video using core's Preview functionality (by clicking "Preview" next to the "Save" button on the node edit form). Is that not sufficient?

Thanks,
Gus

geraldito’s picture

Hi Gus,

First thanks for your module and your answer. The instant feedback of a live preview is more a usability issue I want to offer my users, like the behavior of writing at Stackexchange for example.

I imagine an iframe just beside the field where youtube player and video is shown. Something like Page Preview does for the whole node.

(Another solution for me would be using a preview module and limit the preview to certain fields.)

Thanks,
Gerald

guschilds’s picture

Status: Postponed (maintainer needs more info) » Active

Hey Gerald,

If you could find a preview module that works as needed, that would be the easiest approach. If you were trying to write a patch for the module that accomplished this behavior, I would probably suggest something like the following:

  1. Use hook_menu() to define a new menu item. It's URL should have a wildcard (%) that accepts an encoded YouTube video URL (if that's possible, if not, perhaps pass it as a query parameter) and passes it along to the menu callback.
  2. The menu callback should take the passed URL and use the internal module functions to retrieve the video ID from it. (This is why passing the entire URL to the menu callback would be best, because otherwise you'd have to write new JS to get the ID from the URL, duplicating what is already done in PHP.)
  3. After the menu callback gets the video ID, it should build a render array that would render that field through the right field formatter with the right options. (You might also need to pass the entity type and bundle along to the menu item callback, so that it knows which field formatter options to use.)
  4. Render that render array into markup and return it from the menu callback function.
  5. Add JS to the field widget that takes the entered field value, builds the full path for the menu callback and calls it to retrieve the rendered HTML. That HTML can then be placed into an iframe (still with JS) next to the field.

I hope that helps. We've always tried to keep this module as simple as possible, and the above process is a decent amount of complexity, so I don't know that this would ever make it into the module. That said, I'm happy to review any patches you come up with and provide any feedback if you're stuck.

Gus

geraldito’s picture

Hi Gus,

That's a great step by step guide to accomplish what I need. I'll try to implement it and get back to you for feedback.

Thanks for your great help
Gerald

guschilds’s picture

Status: Active » Closed (works as designed)

Closing due to 2.5 years of inactivity and a lack of patches/interest.