You are here

function media_gallery_form_alter in Media Gallery 7

Same name and namespace in other branches
  1. 7.2 media_gallery.module \media_gallery_form_alter()

Implements hook_form_alter().

File

./media_gallery.module, line 905

Code

function media_gallery_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'media_edit') === 0) {

    // Act on both the regular and multiform versions of the edit form.
    if ($form_id === 'media_edit' || preg_match('/^media_edit_[0-9]+$/', $form_id)) {

      // Prepopulate the media_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);
  }
}