I have made an auto complete feature that searches a service and when a product is selected it adds the data to the node form fields. It's a simple matter of using jQuery val('mydata') on all text fields. Adding the image to the media field in the node form is another matter.

I have made my own media module/plugin so that I can add images from our image CDN. It works great when using it in the media popup. I get an image URL from the auto complete that can be parsed by my module.

I want in code do the same steps as:

  1. Parse the URL (same as entering the url in the Web tab in the media browser and pressing submit)
  2. After parsing it should have saved it temporary to the db (it should eventually become a managed file)
  3. After parse and submit the media field should look updated with a thumbnail of the image and with the Select, Edit and Remove media buttons visible (basically like it would look if you choose manually)

So after I have pressed submit on the node form I guess the field would look like this if debugged inside hook_node_presave():

 'field_image' => 
  array (
    'und' => 
    array (
      0 => 
      array (
        'fid' => '123',
      ),
    ),
  ),

Any ideas how to make this? Or should I make it another way, temporary save the image url and save the image to the node in hook_node_presave() or something? How would I do that?

Comments

Chris Matthews’s picture

Version: 7.x-2.0-unstable6 » 7.x-2.x-dev
Status: Active » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team