I was wondering if anyone has been successful with incorporating an Image field 'type'=>'managed_file'
into a ctools plugin. I created a custom ctools plugin but am having some difficulty with the image field as I am getting an error upon upload. After some searching, it seems like this error could be caused from a file that isn't being included when the form is rebuilt after the ajax request. I've attempted to use the form_load_include
to include the DRUPAL_ROOT/modules/file/file.field.inc
file, and it is being loaded with the form, but I am still receiving this error:
Notice: Undefined index: content_image_pane_edit_form in drupal_retrieve_form() (line 763 of /htdocs/development/includes/form.inc).
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'content_image_pane_edit_form' was given in drupal_retrieve_form() (line 798 of /htdocs/development/includes/form.inc).
Notice: Undefined index: pane_image in file_ajax_upload() (line 271 of /htdocs/development/modules/file/file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of /htdocs/development/modules/file/file.module).
Here is my settings for my Custom Content Type Ctools Plugin:
/*Plugin definition*/
$plugin = array(
'single' => TRUE,
'title' => t('Custom: Content Image Pane'),
'description' => t('This is a custom pane containing a title, textarea and image field.'),
'category' => t('Custom Panes'),
'edit form' => 'content_image_pane_edit_form',
'render callback' => 'content_image_pane_render',
'admin info' => 'content_image_pane_admin_info',
'defaults' => array(
'pane_image' => '',
'pane_content' => '',
)
);
/**
* 'Edit form' callback for the content type.
*/
function content_image_pane_edit_form($form, &$form_state) {
$form['#attributes']['enctype'] = array("multipart/form-data");
form_load_include($form_state, 'inc', 'file', 'file.field');
$conf = $form_state['conf'];
$form['pane_image'] = array(
'#title' => t('Image'),
'#type' => 'managed_file',
'#description' => t('Upload an Image that is associated with this content.'),
'#default_value' => '',
//'#default_value' => !empty($conf['pane_image']) ? variable_get($conf['pane_image']) : '',
'#upload_location' => 'public://panes/',
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpeg jpg')
),
'#array_parents' => array('pane_image')
);
$form['pane_content'] = array(
'#title' => t('Content'),
'#type' => 'text_format',
'#format' => 'full_html',
'#description' => t('Please enter the content for the custom pane here.'),
'#default_value' => $conf['pane_content']['value'],
'#cols' => 40,
'#rows' => 6,
'#resizable' => TRUE,
'#required' => TRUE,
);
return $form;
}
If anyone could point me in the right direction for an answer to this that would be outstanding!