Projet

Général

Profil

Paste
Télécharger (2,63 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / tests / media_module_test.module @ e4215af7

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides Media module pages for testing purposes.
6
 */
7

    
8
/**
9
 * Implements hook_media_browser_plugin_info().
10
 */
11
function media_module_test_media_browser_plugin_info() {
12
  // Allow tests to enable or disable this hook.
13
  if (!variable_get('media_module_test_media_browser_plugin_info', FALSE)) {
14
    return array();
15
  }
16

    
17
  $info['media_module_test'] = array(
18
    'title' => t('Media module test'),
19
    'class' => 'MediaModuleTest',
20
    'weight' => 50,
21
  );
22

    
23
  return $info;
24
}
25

    
26
/**
27
 * Implements hook_media_browser_plugin_info_alter().
28
 */
29
function media_module_test_media_browser_plugin_info_alter(&$info) {
30
  // Allow tests to enable or disable this hook.
31
  if (!variable_get('media_module_test_media_browser_plugin_info_alter', FALSE)) {
32
    return;
33
  }
34

    
35
  $info['media_module_test']['title'] = t('Altered plugin title');
36
}
37

    
38
/**
39
 * Implements hook_media_browser_plugins_alter().
40
 */
41
function media_module_test_media_browser_plugins_alter(&$plugin_output) {
42
  // Allow tests to enable or disable this hook.
43
  if (!variable_get('media_module_test_media_browser_plugins_alter', FALSE)) {
44
    return;
45
  }
46

    
47
  $plugin_output['media_module_test']['test']['#markup'] = '<p>' . t('Altered browser plugin output.') . '</p>';
48
}
49

    
50
/**
51
 * Implements hook_menu().
52
 */
53
function media_module_test_menu() {
54
  $items = array();
55

    
56
  $items['media/test'] = array(
57
    'title' => 'Media test',
58
    'page callback' => 'drupal_get_form',
59
    'page arguments' => array('media_module_test_form'),
60
    'access arguments' => array('view files'),
61
  );
62

    
63
  return $items;
64
}
65

    
66
/**
67
 * Form constructor for testing a 'media' element.
68
 *
69
 * @see media_module_test_form_submit()
70
 * @ingroup forms
71
 */
72
function media_module_test_form($form, &$form_state, $tree = TRUE, $extended = FALSE) {
73
  $form['#tree'] = (bool) $tree;
74

    
75
  $form['nested']['media'] = array(
76
    '#type' => 'media',
77
    '#title' => t('Media'),
78
    '#extended' => (bool) $extended,
79
    '#size' => 13,
80
  );
81

    
82
  $form['textfield'] = array(
83
    '#type' => 'textfield',
84
    '#title' => t('Type a value and ensure it stays'),
85
  );
86

    
87
  $form['submit'] = array(
88
    '#type' => 'submit',
89
    '#value' => t('Save'),
90
  );
91

    
92
  return $form;
93
}
94

    
95
/**
96
 * Form submission handler for media_module_test_form().
97
 */
98
function media_module_test_form_submit($form, &$form_state) {
99
  if ($form['#tree']) {
100
    $fid = $form['nested']['media']['#extended'] ? $form_state['values']['nested']['media']['fid'] : $form_state['values']['nested']['media'];
101
  }
102
  else {
103
    $fid = $form['nested']['media']['#extended'] ? $form_state['values']['media']['fid'] : $form_state['values']['media'];
104
  }
105
  drupal_set_message(t('The file id is %fid.', array('%fid' => $fid)));
106
}