Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Hi, I want to use Media file selector for selecting image in my custom form, but I'm getting some errors.
The form definition:
<?php
$form['image'] = array(
'#type' => 'media',
'#title' => 'Image',
'#description' => '', // there is another error without declared description
'#default_value' => $image, // e.g. $image = array('fid' => 1)
'#media_options' => array(
'global' => array(
'types' => array(
'image' => 'image',
),
'enabledPlugins' => array(
'upload' => 'upload',
'media_default--media_browser_1' => 'media_default--media_browser_1',
),
'schemes' => array(
'public' => 'public',
),
'file_directory' => 'media',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '1 MB',
'uri_scheme' => 'public',
),
),
);
?>
Errors after I clicked to "Select media" button:
- Notice: Undefined index: default_row_class in function template_preprocess_views_view_unformatted() (line: 770 in file .../sites/all/modules/views/theme/theme.inc).
- Notice: Undefined index: row_class_special in function template_preprocess_views_view_unformatted() (line: 771 in file .../sites/all/modules/views/theme/theme.inc).
- Notice: Undefined offset: 0 in function template_preprocess_views_view_unformatted() (line: 796 in file .../sites/all/modules/views/theme/theme.inc).
- Warning: implode() [function.implode]: Invalid arguments passed in function template_preprocess_views_view_unformatted() (line: 796 in file .../sites/all/modules/views/theme/theme.inc).
Everything works, but the errors are annoying. So, I tried to fix this in "media/media.views.inc" file. I added this code on line 90 and it is OK now, but where I'm wrong? Is there some documentation for this form type? Thanks.
<?php
if (!isset($vars['view']->style_plugin->options['default_row_class'])) {
$vars['view']->style_plugin->options['default_row_class'] = TRUE;
}
if (!isset($vars['view']->style_plugin->options['row_class_special'])) {
$vars['view']->style_plugin->options['row_class_special'] = TRUE;
}
?>
Comments
Comment #1
Dave ReidUpdate your Views to the latest 7.x-2.x-dev. It was a bug there that causes these errors.
Comment #2
kybermanGreat, it works now. Thank you.
Comment #3
wirka CreditAttribution: wirka commentedThis code works well for me with Media 7.x-1.x:
This
'#tree' => TRUE
needs if you have more than one media selectors in one form.Comment #4
subhojit777Another example: