You are here

function media_admin in D7 Media 7

Display the list or thumbnails media admin display.

1 string reference to 'media_admin'
media_menu in ./media.module
Implement of hook_menu().

File

includes/media.admin.inc, line 17
This file contains the admin functions for the Media module.

Code

function media_admin($form, $form_state) {
  global $user;
  $path = drupal_get_path('module', 'media');
  $form['#attached'] = array(
    'js' => array(
      $path . '/js/media.admin.js',
    ),
    'css' => array(
      $path . '/css/media.css',
    ),
  );
  if (isset($form_state['values']['operation']) && $form_state['values']['operation'] == 'delete') {
    $form['#attributes']['class'][] = "media-list-operation";
    return media_multiple_delete_confirm($form, $form_state, array_filter($form_state['values']['files']), 'admin/content/media', 'admin/content/media');
  }
  require_once dirname(__FILE__) . '/media.browser.inc';
  media_attach_browser_js($form);
  $types = media_display_types();
  if (arg(3)) {
    $display = arg(3);
    if (!in_array($display, array_keys($types))) {
      exit(drupal_not_found());
    }

    // Save their preference.
    db_merge('media_list_type')
      ->key(array(
      'uid' => $user->uid,
    ))
      ->fields(array(
      'type' => $display,
    ))
      ->execute();
  }
  else {
    $display = db_query("SELECT type FROM {media_list_type} WHERE uid = :uid", array(
      ':uid' => $user->uid,
    ))
      ->fetch();
    if (!$display) {
      $display = 'list';
    }
    else {
      $display = $display->type;
    }
  }

  // Build the display switch.
  $form['switch'] = media_admin_display_switch(array(
    'active display' => $display,
  ));

  // Build the 'Media operations' form.
  $options = array();
  foreach (module_invoke_all('media_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Operations'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
    '#access' => !empty($options),
  );
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'delete',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => array(
      'media_admin_submit',
    ),
    '#validate' => array(
      'media_admin_validate',
    ),
  );
  include_once $types[$display]['file'];
  $form['admin'] = $types[$display]['callback']($form);
  return $form;
}