You are here

ml_dummy.module in Media Library 6

Media Library Dummy module.

File

ml_dummy/ml_dummy.module
View source
<?php

/**
 * @file
 * Media Library Dummy module.
 */

/**
 * Implementation of hook_media_types()
 * Here we define our 'dummy' type
 */
function ml_dummy_media_types() {
  $types = array();
  $types['dummy'] = array(
    'title' => 'Dummy',
    'description' => 'Just some Dummy media content',
    'steps' => 1,
  );
  return $types;
}

/**
 * Implementation of hook_filter_media()
 * See API.txt on media_library for more details.
 */
function ml_dummy_filter_media($content, $preview = FALSE) {
  $output = '';
  if (isset($content['description'])) {
    $output .= '<p>Description: ' . $content['description'] . '</p>';
  }
  if (isset($content['dummy'])) {
    $output .= '<p>Dummy: ' . $content['dummy'] . '</p>';
  }

  // Preview is used for wysiwyg
  if ($preview) {
    $output = '<div class="dummy-preview"><h2>This is just a preview!</h2>' . $output . '</div>';
  }
  return $output;
}

/**
 * Implementation of hook_filter_media_alter() 
 * Just for fun. We add a dummy attribute.
 */
function ml_dummy_filter_media_alter(&$content, $preview = FALSE) {
  if (!$preview) {
    $content['dummy'] .= ' => Some useless dummy content';
  }
}

/**
 * Implementation of hook_media_forms()
 */
function ml_dummy_media_forms($type) {
  switch ($type) {
    case 'dummy':
      $steps = array(
        '1' => array(
          'label' => t('The only step for dummy content'),
          'form id' => 'ml_dummy_form',
        ),
      );
      return $steps;
  }
}

/**
 * Form for modal dialog
 * For updating media, use the contents of $form_state['update']
 */
function ml_dummy_form(&$form, &$form_state) {

  // Check for default value from content being updated
  if (isset($form_state['update'])) {
    $dummy = $form_state['update']['dummy'];
  }
  else {
    $dummy = '';
  }
  $form['dummy_field'] = array(
    '#type' => 'textfield',
    '#title' => t('Dummy Text Field'),
    '#description' => t('Just another dummy field for example'),
    '#size' => 40,
    '#maxlength' => 255,
    '#default_value' => $dummy,
  );
  $form_state['no buttons'] = TRUE;
}
function ml_dummy_form_submit(&$form, &$form_state) {
  if (!empty($form_state['values']['dummy_field'])) {
    $form_state['media_obj']->dummy = $form_state['values']['dummy_field'];
  }
}

/**
* Implementation of hook_media_tag()
*/
function ml_dummy_media_tag($object) {
  if ($object->type == 'dummy') {
    $tag = array(
      'dummy' => $object->dummy,
    );
  }
  return $tag;
}

Functions

Namesort descending Description
ml_dummy_filter_media Implementation of hook_filter_media() See API.txt on media_library for more details.
ml_dummy_filter_media_alter Implementation of hook_filter_media_alter() Just for fun. We add a dummy attribute.
ml_dummy_form Form for modal dialog For updating media, use the contents of $form_state['update']
ml_dummy_form_submit
ml_dummy_media_forms Implementation of hook_media_forms()
ml_dummy_media_tag Implementation of hook_media_tag()
ml_dummy_media_types Implementation of hook_media_types() Here we define our 'dummy' type