You are here

function _media_gallery_add_remove_checkbox in Media Gallery 7

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

Add a "remove" checkbox to the media edit form.

1 call to _media_gallery_add_remove_checkbox()
media_gallery_form_media_edit_alter in ./media_gallery.module
Implements hook_form_FORM_ID_alter().

File

./media_gallery.module, line 1063

Code

function _media_gallery_add_remove_checkbox(&$form, &$form_state, $node) {

  // Keep a reference to the gallery this media item belongs to, so we know
  // what to remove it from.
  $form['#gallery'] = $node;

  // Put the remove checkbox inside the "preview" section, so it shows up
  // underneath the thumbnail.
  // @todo: Move into $form['preview']['remove'] when issue
  // http://drupal.org/node/1055986 get committed.
  $form['remove'] = array(
    '#type' => 'checkbox',
    '#title' => t('Remove from gallery'),
    '#description' => t('The original file remains in your <a href="@library">media library</a>.', array(
      '@library' => url('admin/content/media'),
    )),
    '#access' => node_access('update', $node),
  );

  // Add our own submit handler. We need to add it to both the form and the
  // submit button to make sure it gets fired.
  // Also note that this requires one call to node_save() per media item
  // removed. A better approach, if it were possible, would be to add a submit
  // handler to the entire multiform (see http://drupal.org/node/1033258).
  $form['#submit'][] = 'media_gallery_multiedit_remove_item';
  if (isset($form['actions']['submit']['#submit'])) {
    $form['actions']['submit']['#submit'][] = 'media_gallery_multiedit_remove_item';
  }
}