function media_gallery_form_alter in Media Gallery 7.2
Same name and namespace in other branches
- 7 media_gallery.module \media_gallery_form_alter()
Implements hook_form_alter().
File
- ./
media_gallery.module, line 928
Code
function media_gallery_form_alter(&$form, &$form_state, $form_id) {
// $form_id = 'media_edit_*' by using multiple file editing
// $form_id = 'file_entity_edit' by using regular file edit
if (strpos($form_id, 'media_edit') === 0 || strpos($form_id, 'file_entity_edit')) {
// Act on both the regular and multiform versions of the edit form.
if ($form_id === 'file_entity_edit' || preg_match('/^media_edit_[0-9]+$/', $form_id)) {
// Prepopulate the file_entity_edit form with our best guess at the image title.
if (!empty($form['media_title']) && empty($form['media_title'][LANGUAGE_NONE][0]['value']['#default_value'])) {
$fid = $form['fid']['#value'];
$file = file_load($fid);
if ($file->type === 'image') {
$form['media_title'][LANGUAGE_NONE][0]['value']['#default_value'] = _media_gallery_get_media_title($file);
}
}
// Prepopulate the license field with the correct default.
if ($form['field_license'][LANGUAGE_NONE]['#default_value'] == '_none') {
$form['field_license'][LANGUAGE_NONE]['#default_value'] = 'none';
}
unset($form['field_license'][LANGUAGE_NONE]['#options']['_none']);
}
// Attach JavaScript and CSS needed to alter elements in the form.
_media_gallery_attach_edit_resources($form);
}
}