Download & Extend

Implement a value_callback for media element

Project:Media
Version:7.x-2.x-dev
Component:Media field
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hi,

I am working on a project which requires adding fields to "product" content type dynamically. That means I can not add fields to this content type from "Manage Fields" but need to use form_alter to add fields to "product_node_form".

One of the field needs to of type media selector. I am using this code:

$form['field_videofile1'] = array(
'#title' => 'File Upload',
'#type' => 'media',
);

When the form is rendered it is displaying uploading options and selected file is also getting uploaded to specified folder.

Now after uploading is complete, when I am submitting the form, value of this field is not coming in form state or in POST. I have investigated a little and find that there is an invisible "fid" field is generated for each media selector by "media_element_process" function. In my case name of this field should be field_videofile1_fid. But it is only "fid". As a result I am not getting value of this field in form state.

Please suggest a way out.I am really struck at this point.

AttachmentSizeStatusTest resultOperations
media.JPG108.73 KBIgnored: Check issue status.NoneNone

Comments

#1

Subscribing.

#2

Version:7.x-1.2» 7.x-2.x-dev

<?php
/**
* Implements hook_element_info().
*/
function media_element_info() {
 
$types = array();
 
$types['media'] = array(
   
'#input' => TRUE,
   
'#process' => array('media_element_process'),
   
//'#value_callback' => 'media_element_value',
   
'#element_validate' => array('media_element_validate'),
   
'#theme_wrappers' => array('container'),
   
'#progress_indicator' => 'throbber',
   
'#extended' => FALSE,
   
'#required' => FALSE,
   
'#media_options' => array(
     
'global' => array(
       
'types' => array(), // Example: array('image', 'audio');
       
'schemes' => array(), // Example: array('http', 'ftp', 'flickr');
     
),
    ),
   
'#attributes' => array(
     
'class' => array('media-widget'),
    ),
   
'#attached' => array(
     
'library' => array(
        array(
'media', 'media_browser'),
        ),
    ),
  );
  return
$types;
}
?>

If you check value_callback is commented..we need this one for this to work...something like
http://api.drupal.org/api/drupal/modules%21file%21file.module/function/f...

#3

Any news on this?

Media module is quite awesome, but this is limiting the module integration with other forms not using entity fields.

:(

#4

Title:Adding #type = 'media' to custom field in D7» Implement a value_callback for media element

Ok, on more reason to get this fixed:
#1776300: Respect field settings like minimum - maximum size when used as image field

nobody click here