You are here

function media_media_browser_plugin_view in D7 Media 7

Implements hook_media_browser_plugin_view().

File

./media.media.inc, line 30
Media module integration for the Media module.

Code

function media_media_browser_plugin_view($plugin_name, $params) {
  $path = drupal_get_path('module', 'media');
  $params += array(
    'types' => array(),
    'multiselect' => FALSE,
  );

  // The multiselect parameter is a string.  So we check to see if it is set and
  // adjust the local variable accordingly.
  if ($params['multiselect'] != 'false' && $params['multiselect'] !== FALSE) {
    $params['multiselect'] = TRUE;
  }
  $redirect = array(
    'media/browser',
    array(
      'query' => array(
        'render' => 'media-popup',
      ),
    ),
  );
  switch ($plugin_name) {
    case 'upload':
      $attached = array();
      if ($params['multiselect'] && module_exists('plupload')) {
        $upload_form_id = 'media_add_upload_multiple';
        $attached['js'] = array(
          $path . '/js/plugins/media.upload_multiple.js',
        );
      }
      else {
        $upload_form_id = 'media_add_upload';
      }
      module_load_include('inc', 'media', 'includes/media.pages');
      $upload_form = drupal_get_form($upload_form_id, $params);
      return array(
        '#title' => t('Upload'),
        'form' => array(
          $upload_form,
        ),
        '#attached' => $attached,
      );
      break;
    case 'library':
      return array(
        '#title' => t('Library'),
        '#attached' => array(
          'js' => array(
            $path . '/js/plugins/media.library.js',
          ),
          'css' => array(
            //@todo: should move this.
            $path . '/js/plugins/media.library.css',
          ),
        ),
        '#settings' => array(
          'viewMode' => 'thumbnails',
          'getMediaUrl' => url('media/browser/list'),
        ) + $params,
        '#markup' => '<div id="container"><div id="scrollbox"><ul id="media-browser-library-list" class="media-list-thumbnails"></ul><div id="status"></div></div></div>',
      );
      break;
  }
  return array();
}