media_settings.inc 3.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php
// $Id$

/**
 * @file
 * This file contains the admin functions for the Media module.
 */

/**
 * Provide per content type settings.
 *
 * @param array &form
 *  A form structured array.
 * @param string $type_name
 *  A string representing the content type.
 * @return
 *  Nothing is returned.
 */
function media_settings_content_type(&$form, $type_name = NULL) {
  $form['media'] = array(
21 22
    '#type'        => 'fieldset',
    '#title'       => t('Media settings'),
23 24
    '#collapsible' => TRUE,
    '#group'       => 'additional_settings',
25
  );
26

27 28 29 30
  $type = _media_content_field_types($type_name);

  // Master settings override.
  $form['media']['media_'. $type_name .'_override'] = array(
31
    '#title'         => t($type->name .' overrides default values'),
32 33 34
    '#type'          => 'checkbox',
    '#description'   => t('Override the default settings for this content type.  The options below will only be used if this box is checked.'),
    '#default_value' => variable_get('media_'. $type_name .'_override', NULL),
35 36
  );
  $form['media']['media_'. $type_name .'_enabled'] = array(
37 38 39 40
    '#title'         => t('Enable Media resource browser'),
    '#type'          => 'checkbox',
    '#description'   => t('Enable the Media resource browser for this node type.'),
    '#default_value' => variable_get('media_'. $type_name .'_enabled', NULL),
41
  );
42

43
  // Extract the fields for this node type
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  if (isset($type->fields)) {
    foreach ((array)$type->fields as $field_name => $field) {
      // Create the field identifier
      $form['media'][$field['field_name']] = array(
        '#type'        => 'fieldset',
        '#title'       => t('Field name: !name', array('!name' => $field['widget']['label'])),
        '#collapsible' => 'true',
      );

      // Build a form for each type of module that we have
      foreach (media_registration_kinds() as $kind) {
        // Get all the kinds that match this field
        if ($registrations = media_get_fields($field['type'], $kind)) {
          $options = array();

          foreach ($registrations as $id => $registration) {
            $options[$field['field_name'] .'--'. $id] = $registration['name'] .': '. $registration['description'];
          }

          $form['media'][$field['field_name']]['media_'. $type_name .'_'. $field['field_name'] .'_'. $kind] = array(
            '#title'         => t('Enable !kind options for this field', array('!kind' => $kind)),
            '#description'   => t('Choose which !kind options you would like to have enabled on this field', array('!kind' => $kind)),
            '#type'          => 'checkboxes',
            '#options'       => $options,
            '#default_value' => variable_get('media_'. $type_name .'_'. $field['field_name'] .'_'. $kind, array()),
          );
70 71 72
        }
      }
    }
73

74 75 76 77 78 79 80 81 82 83
    // if we didn't get any additional data, remove this field form
    // this is ugly but hey, sue me
    if (count($form['media'][$field['field_name']]) == 3) {
      unset($form['media'][$field['field_name']]);
    }
  }
}

/**
 * Provide global settings.
84
 *
85
 * Global settings are currently just defaults for content types.
86
 *
87
 * @param $form
88
 *  A form structure.
89 90
 * @return
 *  A form structured array.
91
 */
92 93
function media_settings_global($form) {
  $settings_form = array();
94

95
  $settings_form['media_global_enabled'] = array(
96 97 98 99
    '#title'         => t('Media resource browser'),
    '#type'          => 'checkbox',
    '#description'   => t('Enable or Disable the Media resource browser for all types, unless specifically set for a given type.'),
    '#default_value' => variable_get('media_global_enabled', 1),
100
  );
101

102
  return system_settings_form($settings_form);
103 104 105 106
}

function media_admin($form) {
  return $form;
107
}