You are here

workbench_media.module in Workbench Media 7.2

Same filename and directory in other branches
  1. 7 workbench_media.module

Workbench Media module file for workbench-specific media features.

File

workbench_media.module
View source
<?php

/**
 * @file
 * Workbench Media module file for workbench-specific media features.
 */

/**
 * Implements hook_menu().
 *
 * Provide a UI for uploading media.
 */
function workbench_media_menu() {
  $items = array();
  $items['admin/workbench/media/add'] = array(
    'title' => 'Add Media',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'file_entity_add_upload',
    ),
    'access arguments' => array(
      'use workbench_media add form',
    ),
    'file' => 'file_entity.pages.inc',
    'file path' => drupal_get_path('module', 'file_entity'),
    'type' => MENU_VISIBLE_IN_BREADCRUMB,
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function workbench_media_permission() {
  return array(
    'use workbench_media add form' => array(
      'title' => t('Use the media add form'),
    ),
  );
}

/**
 * Implements hook_workbench_create_alter().
 *
 * Add a media creation section to the workbench "Create Content" tab.
 */
function workbench_media_workbench_create_alter(&$output) {
  if (user_access('use workbench_media add form')) {

    // Mimic node_add_page() theming.
    $items = array(
      array(
        'title' => t('Upload Media'),
        'href' => 'admin/workbench/media/add',
        'localized_options' => array(
          'query' => drupal_get_destination(),
        ),
        'description' => t('Add photos, videos, audio, or other files to the site.'),
      ),
    );
    $output['field_workbench_create_media'] = array(
      '#title' => t('Create media'),
      '#markup' => theme('node_add_list', array(
        'content' => $items,
      )),
      '#theme' => 'workbench_element',
      '#weight' => -1,
    );
  }
}

/**
 * Implementation of hook_views_api().
 */
function workbench_media_views_api() {
  return array(
    'api' => 3,
  );
}

/**
 * Implementation of hook_views_default_views().
 */
function workbench_media_views_default_views() {
  return workbench_load_all_exports('workbench_media', 'views', 'view.inc', 'view');
}

/**
 * Implementation of hook_preprocess_views_view_table().
 *
 * This is done to convert the "type" field to a thumbnail for image files.
 */
function workbench_media_preprocess_views_view_table(&$vars) {

  // Custom handling for the workbench files view
  if ($vars['view']->name == 'workbench_files') {
    foreach ($vars['rows'] as $id => $row) {

      // Is this file an image?
      if (strstr(file_get_mimetype($row['uri']), 'image')) {

        // Is this file on the local file system?
        if (file_exists($row['uri_1'])) {
          $row['filemime'] = theme('image_style', array(
            'path' => $row['uri_1'],
            'style_name' => 'thumbnail',
          ));
        }
      }

      // Assign the databack
      $vars['rows'][$id] = $row;
    }
  }
}