Getting started with Media and File entity – Field your files and reuse them. – Two modules



Getting started with Media and File entity – Field your files and reuse them. – Two modules

0 0


media-getting-started

Getting started with Media and File entity

On Github brandonneil / media-getting-started

Getting started with Media and File entity

Field your files and reuse them.

Brandon Neil / @brandonneil Web/Mobile Application Developer The University of Iowa

Two modules

File entity

  • UI for adding and managing files
  • File types
  • Allows you to add fields to files

Media

  • Media widget for file/image fields
  • Media browser
  • WYSIWYG integration
  • Usage tracking

Media + File entity

Fieldable files with a common media browser.

File Entity Demo

  • Installation
  • Configuration
  • Usage Demos

Media Demo

  • Installation
  • Configuration
  • Usage Demos

Extend

Customize Media Library

Option One - Clone View

Customize Media Library

Option Two - Views API

/**
 * Implements hook_views_default_views_alter().
 */
function MODULENAME_views_default_views_alter(&$views) {
  if (isset($views['media_default'])) {
    // Add a header with help text
    $views['media_default']->display['default']->display_options['header']['area'] = array(
      'id' => 'area',
      'table' => 'views',
      'field' => 'area',
      'empty' => TRUE,
      'content' => '<p>The Library feature allows you to select and embed existing images. You may also link to documents, such as PDF and Word.  To upload new media to the Library, click the Upload button above. </p>
<h2>To embed an image:</h2>
<ul><li>Search for the file name using the filter or index below and then select by clicking on the displayed file</li>
<li>Click the Submit button</li></ul>',
      'format' => 'filtered_html',
      'tokenize' => 0,
    );
  }
}

Alter WYSIWYG display options

/**
 * Implements hook_media_wysiwyg_allowed_view_modes_alter.
 */
function MODULENAME_media_wysiwyg_allowed_view_modes_alter(&$view_modes, $file) {
  // Relabel some options
  switch ($file->type) {
    case 'document':
      $view_modes['default']['label'] = t('Original (Link to file)');
      break;
    case 'image':
      $view_modes['default']['label'] = t('Original (As uploaded)');
      $view_modes['full']['label'] = t('Large (Scale 480x480');
      $view_modes['teaser']['label'] = t('Medium (Scale 220x220)');
      break;
  }
  // Unset the preview view mode
  unset($view_modes['preview']);
}

MOAR Media