Projet

Général

Profil

Révision bf3c8457

Ajouté par Florent Torregrosa il y a plus de 8 ans

Issue #592: Update media to version 7.x-2.0-beta1.

Voir les différences:

drupal7/sites/all/modules/media/includes/media.browser.inc
24 24
    }
25 25
    $files = file_load_multiple($fids);
26 26
    foreach ($files as $file) {
27
      media_browser_build_media_item($file);
27
      $view_mode = isset($params['view_mode']) ? $params['view_mode'] : 'preview';
28
      media_browser_build_media_item($file, $view_mode);
28 29
    }
29 30
    $setting = array('media' => array('selectedMedia' => array_values($files)));
30 31
    drupal_add_js($setting, 'setting');
......
148 149
  return $output;
149 150
}
150 151

  
151
/**
152
 * Attaches media browser javascript to an element.
153
 *
154
 * @param array $element
155
 *   The element array to attach to.
156
 */
157
function media_attach_browser_js(&$element) {
158
  $javascript = media_browser_js();
159
  foreach ($javascript as $key => $definitions) {
160
    foreach ($definitions as $definition) {
161
      $element['#attached'][$key][] = $definition;
162
    }
163
  }
164
}
165

  
166
/**
167
 * Helper function to define browser javascript.
168
 */
169
function media_browser_js() {
170
  $settings = array(
171
    'browserUrl' => url('media/browser', array(
172
      'query' => array(
173
        'render' => 'media-popup'
174
      ))
175
    ),
176
    'styleSelectorUrl' => url('media/-media_id-/format-form', array(
177
      'query' => array(
178
        'render' => 'media-popup'
179
      ))
180
    ),
181
    'dialogOptions' => array(
182
      'dialogclass' => variable_get('media_dialogclass', 'media-wrapper'),
183
      'modal' => (boolean)variable_get('media_modal', TRUE),
184
      'draggable' => (boolean)variable_get('media_draggable', FALSE),
185
      'resizable' => (boolean)variable_get('media_resizable', FALSE),
186
      'minwidth' => (int)variable_get('media_minwidth', 500),
187
      'width' => (int)variable_get('media_width', 670),
188
      'height' => (int)variable_get('media_height', 280),
189
      'position' => variable_get('media_position', 'center'),
190
      'overlay' => array(
191
        'backgroundcolor' => variable_get('media_backgroundcolor', '#000000'),
192
        'opacity' => (float)variable_get('media_opacity', 0.4),
193
      ),
194
      'zindex' => (int)variable_get('media_zindex', 10000),
195
    ),
196
  );
197

  
198
  return array(
199
    'library' => array(
200
      array('media', 'media_browser'),
201
    ),
202
    'js' => array(
203
      array(
204
       'data' => array('media' => $settings),
205
       'type' => 'setting',
206
      ),
207
    ),
208
  );
209
}
210

  
211 152
/**
212 153
 * Menu callback for testing the media browser.
213 154
 */
214 155
function media_browser_testbed($form) {
215
  media_attach_browser_js($form);
156
  $form['#attached']['library'][] = array('media', 'media_browser');
157
  $form['#attached']['library'][] = array('media', 'media_browser_settings');
216 158

  
217 159
  $form['test_element'] = array(
218 160
    '#type' => 'media',
......
290 232
}
291 233

  
292 234
/**
293
 * Adds properties to the file.
235
 * Adds additional properties to a file which are needed by the browser JS code.
294 236
 *
295
 * Additional properties on this file are needed by the media browser JS code.
237
 * @param object $file
238
 *   A Drupal file object.
296 239
 */
297
function media_browser_build_media_item($file) {
298
  $preview = media_get_thumbnail_preview($file);
240
function media_browser_build_media_item($file, $view_mode = 'preview') {
241
  $preview = media_get_thumbnail_preview($file, NULL, $view_mode);
299 242
  $file->preview = drupal_render($preview);
300 243
  $file->url = file_create_url($file->uri);
301 244
}
drupal7/sites/all/modules/media/includes/media.fields.inc
15 15
      'label' => t('Media browser'),
16 16
      'field types' => array('file', 'image'),
17 17
      'settings' => array(
18
        'allowed_types' => array('image'),
18
        'allowed_types' => array(
19
          'image' => 'image',
20
        ),
19 21
        'browser_plugins' => array(),
20
        'allowed_schemes' => array('public', 'private'),
22
        'allowed_schemes' => array(
23
          'public' => 'public',
24
        ),
21 25
      ),
22 26
      'behaviors' => array(
23 27
        'multiple values' => FIELD_BEHAVIOR_CUSTOM,
......
77 81
 * Implements hook_field_widget_form().
78 82
 */
79 83
function media_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
80

  
81
  // Add display_field setting to field because media_field_widget_form() assumes it is set.
82
  if (!isset($field['settings']['display_field'])) {
83
    $field['settings']['display_field'] = 0;
84
  }
85

  
86 84
  $defaults = array(
87 85
    'fid' => 0,
88 86
    'display' => !empty($field['settings']['display_default']),
......
164 162
    $elements['#description'] = $element['#description'];
165 163
    $elements['#field_name'] = $element['#field_name'];
166 164
    $elements['#language'] = $element['#language'];
167
    $elements['#display_field'] = $field['settings']['display_field'];
165
    $elements['#display_field'] = intval(!empty($field['settings']['display_field']));
168 166

  
169 167
    // Add some properties that will eventually be added to the media upload
170 168
    // field. These are added here so that they may be referenced easily through
......
185 183
    // If the display field is present make sure its unchecked value is saved.
186 184
    $field = field_widget_field($element, $form_state);
187 185
    if (empty($input['display'])) {
188
      $input['display'] = $field['settings']['display_field'] ? 0 : 1;
186
      $input['display'] = intval(!empty($field['settings']['display_field']));
189 187
    }
190 188
  }
191 189

  
......
450 448
    // "operations" column.
451 449
    $operations_elements = array();
452 450
    foreach (element_children($widget) as $sub_key) {
453
      if (isset($widget[$sub_key]['#type']) && $widget[$sub_key]['#type'] == 'submit') {
451
      if (isset($widget[$sub_key]['#type']) && ($widget[$sub_key]['#type'] == 'submit' || $widget[$sub_key]['#type'] == 'link')) {
454 452
        hide($widget[$sub_key]);
455 453
        $operations_elements[] = &$widget[$sub_key];
456 454
      }
......
543 541
    'media_large_icon' => array(
544 542
      'label' => t('Large filetype icon'),
545 543
      'field types' => array('file'),
544
      'settings' => array(
545
        'image_style' => '',
546
      ),
546 547
    ),
547 548
  );
549

  
548 550
  return $formatters;
549 551
}
550 552

  
553
/**
554
 * Implements hook_field_formatter_settings_form().
555
 *
556
 * Legacy support for the "Large filetype icon" file field formatter.
557
 * @see media_field_formatter_info()
558
 */
559
function media_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
560
  $display = $instance['display'][$view_mode];
561
  $settings = $display['settings'];
562

  
563
  $image_styles = image_style_options(FALSE, PASS_THROUGH);
564
  $element['image_style'] = array(
565
    '#title' => t('Image style'),
566
    '#type' => 'select',
567
    '#default_value' => $settings['image_style'],
568
    '#empty_option' => t('None (original image)'),
569
    '#options' => $image_styles,
570
  );
571

  
572
  return $element;
573
}
574

  
575
/**
576
 * Implements hook_field_formatter_settings_summary().
577
 *
578
 * Legacy support for the "Large filetype icon" file field formatter.
579
 * @see media_field_formatter_info()
580
 */
581
function media_field_formatter_settings_summary($field, $instance, $view_mode) {
582
  $display = $instance['display'][$view_mode];
583
  $settings = $display['settings'];
584

  
585
  $summary = array();
586

  
587
  $image_styles = image_style_options(FALSE, PASS_THROUGH);
588
  // Unset possible 'No defined styles' option.
589
  unset($image_styles['']);
590
  // Styles could be lost because of enabled/disabled modules that defines
591
  // their styles in code.
592
  if (isset($image_styles[$settings['image_style']])) {
593
    $summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
594
  }
595
  else {
596
    $summary[] = t('Original image');
597
  }
598

  
599
  return implode('<br />', $summary);
600
}
601

  
551 602
/**
552 603
 * Implements hook_field_formatter_view().
553 604
 *
......
558 609
  $element = array();
559 610

  
560 611
  if ($display['type'] == 'media_large_icon') {
561
    // Use the media_thumbnail image style so that the output in media browser
562
    // is consistent.
563 612
    foreach ($items as $delta => $item) {
564 613
      $element[$delta] = array(
565 614
        '#theme' => 'media_formatter_large_icon',
566 615
        '#file' => (object) $item,
616
        '#style_name' => $display['settings']['image_style'],
567 617
      );
568 618
    }
569 619
  }
drupal7/sites/all/modules/media/js/media.browser.js
30 30
      }
31 31
    };
32 32
    var activeTab = Drupal.media.browser.tabFromHash();
33
    $('#media-browser-tabset').tabs({
33
    $('#media-browser-tabset').once('MediaBrowser').tabs({
34 34
      selected: activeTab, // jquery < 1.9
35 35
      active: activeTab, // jquery >= 1.9
36 36
      show: showFunc, // jquery ui < 1.8
......
107 107
  Drupal.media.browser.selectedMedia = selectedMedia;
108 108
};
109 109

  
110
Drupal.media.browser.selectMediaAndSubmit = function (selectedMedia) {
111
  Drupal.media.browser.selectedMedia = selectedMedia;
112
  Drupal.media.browser.submit();
113
};
114

  
110 115
Drupal.media.browser.finalizeSelection = function () {
111 116
  if (!Drupal.media.browser.selectedMedia) {
112 117
    throw new exception(Drupal.t('Cannot continue, nothing selected'));
drupal7/sites/all/modules/media/js/plugins/media.views.js
80 80
  // Reset the list of selected files
81 81
  Drupal.media.browser.selectMedia([]);
82 82

  
83
  // Catch double click to submit a single item.
84
  $('.view-content .media-item', view).bind('dblclick', function () {
85
    var fid = $(this).closest('.media-item[data-fid]').data('fid'),
86
      selectedFiles = new Array();
87

  
88
    // Remove all currently selected files
89
    $('.view-content .media-item', view).removeClass('selected');
90

  
91
    // Mark it as selected
92
    $(this).addClass('selected');
93

  
94
    // Because the files are added using drupal_add_js() and due to the fact
95
    // that drupal_get_js() runs a drupal_array_merge_deep() which re-numbers
96
    // numeric key values, we have to search in Drupal.settings.media.files
97
    // for the matching file ID rather than referencing it directly.
98
    for (index in Drupal.settings.media.files) {
99
      if (Drupal.settings.media.files[index].fid == fid) {
100
        selectedFiles.push(Drupal.settings.media.files[index]);
101

  
102
        // If multiple tabs contains the same file, it will be present in the
103
        // files-array multiple times, so we break out early so we don't have
104
        // it in the selectedFiles array multiple times.
105
        // This would interfer with multi-selection, so...
106
        break;
107
      }
108
    }
109
    Drupal.media.browser.selectMediaAndSubmit(selectedFiles);
110
  });
111

  
112

  
83 113
  // Catch the click on a media item
84 114
  $('.view-content .media-item', view).bind('click', function () {
85 115
    var fid = $(this).closest('.media-item[data-fid]').data('fid'),
drupal7/sites/all/modules/media/media.api.php
14 14
 * @return array
15 15
 *   The unique URI for the file, based on its stream wrapper, or NULL.
16 16
 *
17
 * @see hook_media_parse_alter()
17 18
 * @see media_parse_to_file()
18 19
 * @see media_add_from_url_validate()
19 20
 */
......
27 28
  }
28 29
}
29 30

  
31
/**
32
 * Alters the parsing of urls and embedded codes into unique URIs.
33
 *
34
 * @param string $success
35
 *   The unique URI for the file, based on its stream wrapper, or NULL.
36
 * @param array $context
37
 *   A nested array of contextual information containing the following keys:
38
 *   - url: The original URL or embed code to parse.
39
 *   - module: The name of the module which is attempting to parse the url or
40
 *     embedded code into a unique URI.
41
 *
42
 * @see hook_media_parse()
43
 * @see hook_media_browser_plugin_info()
44
 * @see media_get_browser_plugin_info()
45
 */
46
function hook_media_parse_alter(&$success, $context) {
47
  $url = $context['url'];
48
  $url_info = parse_url($url);
49

  
50
  // Restrict users to only embedding secure links.
51
  if ($url_info['scheme'] != 'https') {
52
    $success = NULL;
53
  }
54

  
55
  // Use a custom handler for detecting YouTube videos.
56
  if ($context['module' == 'media_youtube']) {
57
    $handler = new CustomYouTubeHandler($url);
58
    $success = $handler->parse($url);
59
  }
60
}
61

  
30 62
/**
31 63
 * Returns a list of plugins for the media browser.
32 64
 *
......
99 131
 * @see media_set_browser_params()
100 132
 */
101 133
function hook_media_browser_params_alter(&$stored_params) {
134
  $stored_params['view_mode'] = 'custom';
102 135
  $stored_params['types'][] = 'document';
103 136
  unset($stored_params['enabledPlugins'][0]);
104 137
}
drupal7/sites/all/modules/media/media.file_default_displays.inc
15 15
  $file_display = new stdClass();
16 16
  $file_display->api_version = 1;
17 17
  $file_display->name = 'audio__preview__file_field_media_large_icon';
18
  $file_display->weight = 50;
18
  $file_display->weight = 49;
19 19
  $file_display->status = TRUE;
20
  $file_display->settings = '';
20
  $file_display->settings = array(
21
    'image_style' => 'media_thumbnail',
22
  );
21 23
  $file_displays['audio__preview__file_field_media_large_icon'] = $file_display;
22 24

  
23 25
  // Document previews should be displayed using a large filetype icon.
24 26
  $file_display = new stdClass();
25 27
  $file_display->api_version = 1;
26 28
  $file_display->name = 'document__preview__file_field_media_large_icon';
27
  $file_display->weight = 50;
29
  $file_display->weight = 49;
28 30
  $file_display->status = TRUE;
29
  $file_display->settings = '';
31
  $file_display->settings = array(
32
    'image_style' => 'media_thumbnail',
33
  );
30 34
  $file_displays['document__preview__file_field_media_large_icon'] = $file_display;
31 35

  
32 36
  // Image previews should be displayed using a large filetype icon.
33 37
  $file_display = new stdClass();
34 38
  $file_display->api_version = 1;
35 39
  $file_display->name = 'image__preview__file_field_media_large_icon';
36
  $file_display->weight = 50;
40
  $file_display->weight = 49;
37 41
  $file_display->status = TRUE;
38
  $file_display->settings = '';
42
  $file_display->settings = array(
43
    'image_style' => 'media_thumbnail',
44
  );
39 45
  $file_displays['image__preview__file_field_media_large_icon'] = $file_display;
40 46

  
41 47
  // Video previews should be displayed using a large filetype icon.
42 48
  $file_display = new stdClass();
43 49
  $file_display->api_version = 1;
44 50
  $file_display->name = 'video__preview__file_field_media_large_icon';
45
  $file_display->weight = 50;
51
  $file_display->weight = 49;
46 52
  $file_display->status = TRUE;
47
  $file_display->settings = '';
53
  $file_display->settings = array(
54
    'image_style' => 'media_thumbnail',
55
  );
48 56
  $file_displays['video__preview__file_field_media_large_icon'] = $file_display;
49 57

  
50 58
  return $file_displays;
drupal7/sites/all/modules/media/media.info
24 24
; We have to add a fake version so Git checkouts do not fail Media dependencies
25 25
version = 7.x-2.x-dev
26 26

  
27
; Information added by Drupal.org packaging script on 2014-10-04
28
version = "7.x-2.0-alpha4"
27
; Information added by Drupal.org packaging script on 2015-07-14
28
version = "7.x-2.0-beta1"
29 29
core = "7.x"
30 30
project = "media"
31
datestamp = "1412422430"
31
datestamp = "1436895542"
32 32

  
drupal7/sites/all/modules/media/media.install
104 104
function media_requirements($phase) {
105 105
  $t = get_t();
106 106
  // Make sure that file_entity module is 2.x version.
107
  // We can't add this check in .info file because drupal.org testbot cant
107
  // We can't add this check in .info file because drupal.org testbot can't
108 108
  // handle it. See #1734648.
109 109
  $requirements = array();
110 110

  
......
139 139
 * Create the media_type table from the media_types variable.
140 140
 */
141 141
function media_update_7002() {
142
  if (db_table_exists('media_type')) {
143
    return;
144
  }
145

  
142 146
  $schema['media_type'] = array(
143 147
    'description' => 'Stores the settings for media types.',
144 148
    'fields' => array(
......
190 194
  db_create_table('media_type', $schema['media_type']);
191 195

  
192 196
  drupal_load('module', 'media');
193
  $old_types = variable_get('media_types');
197
  $old_types = variable_get('media_types', array());
194 198
  foreach ($old_types as $type) {
195 199
    // Was an error in the original creation.
196 200
    if (isset($type->callbacks)) {
......
496 500
  }
497 501
}
498 502

  
503
/**
504
 * Rerun media_update_7002() due to a typo that would prevent table creation.
505
 */
506
function media_update_7021() {
507
  media_update_7002();
508
}
509

  
499 510
/**
500 511
 * Replace 'view media' perm from all users having the role with 'view file'.
501 512
 */
......
1160 1171
}
1161 1172

  
1162 1173
/**
1163
 * Accommodate the introduction of a new permission which restricts access to
1164
 * the media browser by granting it to existing users who were able to access
1165
 * it.
1174
 * Grant existing user access to new media browser permission.
1166 1175
 */
1167 1176
function media_update_7226() {
1168 1177
  $roles = user_roles(FALSE, 'create files');
drupal7/sites/all/modules/media/media.module
358 358
  }
359 359

  
360 360
  // Add a validation function to any field instance which uses the media widget
361
  // to ensure that the upload destination scheme is one of the allowed schemes.
362
  if ($form['instance']['widget']['type']['#value'] == 'media_generic') {
361
  // to ensure that the upload destination scheme is one of the allowed schemes
362
  // if any defined by settings.
363
  if ($form['instance']['widget']['type']['#value'] == 'media_generic' && isset($form['#field']['settings']['uri_scheme'])) {
363 364
    $form['#validate'][] = 'media_field_instance_validate';
364 365
  }
365 366

  
......
378 379
 * allowed schemes.
379 380
 */
380 381
function media_field_instance_validate($form, &$form_state) {
381
  $allowed_schemes = $form_state['values']['instance']['widget']['settings']['allowed_schemes'];
382
  $allowed_schemes = array_filter($form_state['values']['instance']['widget']['settings']['allowed_schemes']);
382 383
  $upload_destination = $form_state['values']['field']['settings']['uri_scheme'];
383 384

  
384
  if (!in_array($upload_destination, array_filter($allowed_schemes))) {
385
  if (!empty($allowed_schemes) && !in_array($upload_destination, $allowed_schemes)) {
385 386
    form_set_error('allowed_schemes', t('The upload destination must be one of the allowed schemes.'));
386 387
  }
387 388
}
......
393 394
  // If we're in the media browser, set the #media_browser key to true
394 395
  // so that if an ajax request gets sent to a different path, the form
395 396
  // still uses the media_browser_form_submit callback.
396
  if (current_path() == 'media/browser' && $form_id != 'views_exposed_form') {
397
    $form_state['#media_browser'] = TRUE;
397
  if (current_path() == 'media/browser') {
398
    if ($form_id == 'views_exposed_form') {
399
      $form['render'] = array('#type' => 'hidden', '#value' => 'media-popup');
400
      $form['#action'] = '/media/browser';
401
    } else {
402
      $form_state['#media_browser'] = TRUE;
403
    }
398 404
  }
399 405

  
400 406
  // If the #media_browser key isset and is true we are using the browser
......
478 484
    ),
479 485
  );
480 486

  
487
  // Settings for the dialog etc.
488
  $settings = array(
489
    'browserUrl' => url('media/browser', array(
490
      'query' => array(
491
        'render' => 'media-popup'
492
      ))
493
    ),
494
    'styleSelectorUrl' => url('media/-media_id-/format-form', array(
495
      'query' => array(
496
        'render' => 'media-popup'
497
      ))
498
    ),
499
    'dialogOptions' => array(
500
      'dialogclass' => variable_get('media_dialogclass', 'media-wrapper'),
501
      'modal' => (boolean)variable_get('media_modal', TRUE),
502
      'draggable' => (boolean)variable_get('media_draggable', FALSE),
503
      'resizable' => (boolean)variable_get('media_resizable', FALSE),
504
      'minwidth' => (int)variable_get('media_minwidth', 500),
505
      'width' => (int)variable_get('media_width', 670),
506
      'height' => (int)variable_get('media_height', 280),
507
      'position' => variable_get('media_position', 'center'),
508
      'overlay' => array(
509
        'backgroundcolor' => variable_get('media_backgroundcolor', '#000000'),
510
        'opacity' => (float)variable_get('media_opacity', 0.4),
511
      ),
512
      'zindex' => (int)variable_get('media_zindex', 10000),
513
    ),
514
  );
515

  
516
  $libraries['media_browser_settings'] = array(
517
    'title' => 'Media browser settings',
518
    'js' => array(
519
      0 => array(
520
        'data' => array(
521
          'media' => $settings,
522
        ),
523
        'type' => 'setting',
524
      ),
525
    ),
526
  );
527

  
481 528
  foreach ($libraries as &$library) {
482 529
    $library += $common;
483 530
  }
......
538 585
  $url = trim($url);
539 586
  foreach (module_implements('media_parse') as $module) {
540 587
    $success = module_invoke($module, 'media_parse', $url);
588
    $context = array(
589
      'url' => $url,
590
      'module' => $module,
591
    );
592
    drupal_alter('media_parse', $success, $context);
541 593
    if (isset($success)) {
542 594
      return $success;
543 595
    }
......
660 712
  ctools_include('modal');
661 713
  ctools_include('ajax');
662 714
  ctools_modal_add_js();
715

  
716
  // Append the '-upload' to the #id so the field label's 'for' attribute
717
  // corresponds with the textfield element.
718
  $original_id = $element['#id'];
719
  $element['#id'] .= '-upload';
663 720
  $fid = isset($element['#value']['fid']) ? $element['#value']['fid'] : 0;
664 721

  
665 722
  // Set some default element properties.
......
668 725

  
669 726
  $ajax_settings = array(
670 727
    'path' => 'media/ajax/' . implode('/', $element['#array_parents']) . '/' . $form['form_build_id']['#value'],
671
    'wrapper' => $element['#id'] . '-ajax-wrapper',
728
    'wrapper' => $original_id . '-ajax-wrapper',
672 729
    'effect' => 'fade',
673 730
  );
674 731

  
......
769 826
    )
770 827
  );
771 828

  
772
  module_load_include('inc', 'media', 'includes/media.browser');
773
  media_attach_browser_js($element);
829
  $element['#attached']['library'][] = array('media', 'media_browser');
830
  $element['#attached']['library'][] = array('media', 'media_browser_settings');
774 831

  
775 832
  // Prefix and suffix used for Ajax replacement.
776
  $element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
833
  $element['#prefix'] = '<div id="' . $original_id . '-ajax-wrapper">';
777 834
  $element['#suffix'] = '</div>';
778 835

  
779 836
  return $element;
......
1015 1072
}
1016 1073

  
1017 1074
/**
1018
 * Media thumbnail render function.
1075
 * Generates a thumbnail preview of a file.
1019 1076
 *
1020
 * Returns a renderable array with the necessary classes to support a media
1021
 * thumbnail. Also provides default fallback images if no image is available.
1077
 * Provides default fallback images if an image of the file cannot be generated.
1022 1078
 *
1023 1079
 * @param object $file
1024 1080
 *   A Drupal file object.
1081
 * @param boolean $link
1082
 *   (optional) Boolean indicating whether the thumbnail should be linked to the
1083
 *   file. Defaults to FALSE.
1084
 * @param string $view_mode
1085
 *   (optional) The view mode to use when rendering the thumbnail. Defaults to
1086
 *   'preview'.
1025 1087
 *
1026 1088
 * @return array
1027
 *   Renderable array.
1089
 *   Renderable array suitable for drupal_render() with the necessary classes
1090
 *   and CSS to support a media thumbnail.
1028 1091
 */
1029
function media_get_thumbnail_preview($file, $link = NULL) {
1092
function media_get_thumbnail_preview($file, $link = FALSE, $view_mode = 'preview') {
1030 1093
  // If a file has an invalid type, allow file_view_file() to work.
1031 1094
  if (!file_type_is_enabled($file->type)) {
1032 1095
    $file->type = file_get_type($file);
1033 1096
  }
1034 1097

  
1035
  $preview = file_view_file($file, 'preview');
1098
  $preview = file_view_file($file, $view_mode);
1036 1099
  $preview['#show_names'] = TRUE;
1037 1100
  $preview['#add_link'] = $link;
1038 1101
  $preview['#theme_wrappers'][] = 'media_thumbnail';
1039 1102
  $preview['#attached']['css'][] = drupal_get_path('module', 'media') . '/css/media.css';
1103

  
1040 1104
  return $preview;
1041 1105
}
1042 1106

  
......
1278 1342
/**
1279 1343
 * Returns metadata describing Media browser plugins.
1280 1344
 *
1345
 * @return
1346
 *   An associative array of plugin information, keyed by plugin.
1347
 *
1281 1348
 * @see hook_media_browser_plugin_info()
1282 1349
 * @see hook_media_browser_plugin_info_alter()
1283 1350
 */
......
1285 1352
  $info = &drupal_static(__FUNCTION__);
1286 1353

  
1287 1354
  if (!isset($info)) {
1288
    $cid = 'media:browser:plugin:info:' . $GLOBALS['language']->language;
1289
    if ($cache = cache_get($cid)) {
1290
      $info = $cache->data;
1291
    }
1292
    else {
1293
      $info = module_invoke_all('media_browser_plugin_info');
1294
      drupal_alter('media_browser_plugin_info', $info);
1295
      cache_set($cid, $info);
1296
    }
1355
    $info = module_invoke_all('media_browser_plugin_info');
1356
    drupal_alter('media_browser_plugin_info', $info);
1297 1357
  }
1298 1358

  
1299 1359
  return $info;
drupal7/sites/all/modules/media/media.views.inc
74 74
  $files = file_load_multiple($fids);
75 75

  
76 76
  // Render the preview for each file.
77
  $params = media_get_browser_params();
78
  $view_mode = isset($params['view_mode']) ? $params['view_mode'] : 'preview';
79

  
77 80
  foreach ($vars['rows'] as $index => $row) {
78 81
    $file = $files[$row->fid];
79 82
    // Add url/preview to the file object.
80
    media_browser_build_media_item($file);
83
    media_browser_build_media_item($file, $view_mode);
81 84
    $vars['rows'][$index] = $file;
82 85
    $vars['rows'][$index]->preview = $file->preview;
83 86
  }
......
126 129
 * Implements hook_views_invalidate_cache().
127 130
 */
128 131
function media_views_invalidate_cache() {
129
  cache_clear_all('media:browser:plugin', 'cache', TRUE);
130 132
  drupal_static_reset('media_get_browser_plugin_info');
131 133
}
drupal7/sites/all/modules/media/modules/media_bulk_upload/includes/media_bulk_upload.pages.inc
27 27
  $form = call_user_func_array('multiform_get_form', $forms);
28 28
  $form['#attributes']['class'][] = 'media-bulk-upload-multiedit-form';
29 29

  
30
  // Add the title to each 'subform'.
30
  // Improve the display of each file form.
31 31
  foreach (element_children($form['multiform']) as $key) {
32 32
    $fid = $form['multiform'][$key]['fid']['#value'];
33 33
    $file = $files[$fid];
34

  
35
    // Add the filename to each 'subform'.
34 36
    $title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
35 37
    $form['multiform'][$key]['#prefix'] = '<h2>' . $title . '</h2>';
38

  
39
    // Remove the 'replace file' functionality.
40
    $form['multiform'][$key]['replace_upload']['#access'] = FALSE;
41

  
42
    // Remove any actions.
36 43
    $form['multiform'][$key]['actions']['#access'] = FALSE;
44

  
45
    // Hide additional settings under a collapsible fieldset.
46
    $form['multiform'][$key]['settings'] = array(
47
      '#type' => 'fieldset',
48
      '#title' => t('Additional settings'),
49
      '#weight' => 99,
50
      '#collapsible' => TRUE,
51
      '#collapsed' => TRUE,
52
      // FAPI #collapsed and #collapsible not available in a render array.
53
      '#attached' => array(
54
        'js' => array(
55
          'misc/form.js',
56
          'misc/collapse.js',
57
        ),
58
      ),
59
      '#attributes' => array(
60
        'class' => array('collapsible', 'collapsed'),
61
      ),
62
    );
63

  
64
    $form['multiform'][$key]['settings']['additional_settings'] = $form['multiform'][$key]['additional_settings'];
65
    unset($form['multiform'][$key]['additional_settings']);
37 66
  }
38 67

  
39 68
  if (isset($form['buttons']['Delete'])) {
drupal7/sites/all/modules/media/modules/media_bulk_upload/media_bulk_upload.info
7 7
dependencies[] = multiform
8 8
dependencies[] = plupload
9 9

  
10
test_dependencies[] = multiform
11
test_dependencies[] = plupload
12

  
10 13
files[] = includes/MediaBrowserBulkUpload.inc
14
files[] = tests/media_bulk_upload.test
11 15

  
12
; Information added by Drupal.org packaging script on 2014-10-04
13
version = "7.x-2.0-alpha4"
16
; Information added by Drupal.org packaging script on 2015-07-14
17
version = "7.x-2.0-beta1"
14 18
core = "7.x"
15 19
project = "media"
16
datestamp = "1412422430"
20
datestamp = "1436895542"
17 21

  
drupal7/sites/all/modules/media/modules/media_bulk_upload/media_bulk_upload.module
154 154
  if ($form_id != 'media_edit' && (strpos($form_id, 'media_edit') === 0)) {
155 155
    $forms[$form_id] = array(
156 156
      'callback' => 'file_entity_edit',
157
      'wrapper_callback' => 'media_bulk_upload_prepare_edit_form',
157 158
    );
158 159
  }
159 160
  return $forms;
160 161
}
161 162

  
163
function media_bulk_upload_prepare_edit_form($form, &$form_state) {
164
  form_load_include($form_state, 'inc', 'file_entity', 'file_entity.pages');
165
}
166

  
162 167
/**
163 168
 * Access callback for the media-multi form.
164 169
 *
drupal7/sites/all/modules/media/modules/media_bulk_upload/tests/media_bulk_upload.test
1
<?php
2

  
3
/**
4
 * @file
5
 * Tests for media_bulk_upload.module.
6
 */
7

  
8
/**
9
 * Provides methods specifically for testing Media Bulk Upload module's bulk file uploading capabilities.
10
 */
11
class MediaBulkUploadTestHelper extends DrupalWebTestCase {
12
  function setUp() {
13
    // Since this is a base class for many test cases, support the same
14
    // flexibility that DrupalWebTestCase::setUp() has for the modules to be
15
    // passed in as either an array or a variable number of string arguments.
16
    $modules = func_get_args();
17
    if (isset($modules[0]) && is_array($modules[0])) {
18
      $modules = $modules[0];
19
    }
20
    $modules[] = 'media_bulk_upload';
21
    parent::setUp($modules);
22
  }
23

  
24
  /**
25
   * Retrieves a sample file of the specified type.
26
   */
27
  function getTestFile($type_name, $size = NULL) {
28
    // Get a file to upload.
29
    $file = current($this->drupalGetTestFiles($type_name, $size));
30

  
31
    // Add a filesize property to files as would be read by file_load().
32
    $file->filesize = filesize($file->uri);
33

  
34
    return $file;
35
  }
36

  
37
  /**
38
   * Get a file from the database based on its filename.
39
   *
40
   * @param $filename
41
   *   A file filename, usually generated by $this->randomName().
42
   * @param $reset
43
   *   (optional) Whether to reset the internal file_load() cache.
44
   *
45
   * @return
46
   *   A file object matching $filename.
47
   */
48
  function getFileByFilename($filename, $reset = FALSE) {
49
    $files = file_load_multiple(array(), array('filename' => $filename), $reset);
50
    // Load the first file returned from the database.
51
    $returned_file = reset($files);
52
    return $returned_file;
53
  }
54
}
55

  
56
/**
57
 * Test bulk file editing.
58
 */
59
class MediaBulkUploadEditTestCase extends MediaBulkUploadTestHelper {
60
  public static function getInfo() {
61
    return array(
62
      'name' => 'Bulk file editing',
63
      'description' => 'Test file editing with multiple files.',
64
      'group' => 'Media Bulk Upload',
65
      'dependencies' => array('multiform', 'plupload'),
66
    );
67
  }
68

  
69
  function setUp() {
70
    parent::setUp();
71

  
72
    $web_user = $this->drupalCreateUser(array('create files', 'edit any document files', 'edit any image files'));
73
    $this->drupalLogin($web_user);
74
  }
75

  
76
  /**
77
   * Tests editing with multiple files.
78
   */
79
  function testBulkFileEditing() {
80
    $files = array();
81

  
82
    // Create multiple files for testing.
83
    foreach (array('image', 'text') as $type_name) {
84
      $test_file = $this->getTestFile($type_name);
85
      $file = file_save($test_file);
86
      $files[$file->fid] = $file;
87
    }
88

  
89
    // Visit the bulk file edit page and verify that it performs as expected.
90
    $path = media_bulk_upload_file_edit_url(array_keys($files));
91
    $this->drupalGet($path);
92

  
93
    foreach ($files as $file) {
94
      // Verify that a filename for each file is present on the page.
95
      $title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
96
      $this->assertRaw('<h2>' . $title . '</h2>', 'The file has the correct filename.');
97

  
98
      // Verify that the 'replace file' functionality is disabled.
99
      $this->assertNoField('multiform[media_edit_' . $file->fid . '_' . ($file->fid - 1) . '][files][replace_upload]', 'Replace file field found.');
100

  
101
      // Verify that the action buttons have been removed.
102
      $this->assertNoLinkByHref('file/' . $file->fid);
103
    }
104
  }
105
}
drupal7/sites/all/modules/media/modules/media_internet/media_internet.api.php
6 6
 */
7 7

  
8 8
/**
9
 * Implements hook_media_internet_providers().
9
 * Returns a list of Internet media providers for URL/embed code testing.
10 10
 *
11
 * Implementors return an multidim array, keyed by a class name with the
12
 * following elements:
13
 * - title
14
 * - image (optional)
15
 * - hidden: bool If the logo should be shown on form. (optional)
16
 * - weight (optional)
11
 * @return array
12
 *   A nested array of provider information, keyed by class name. This class
13
 *   must implement a claim() method and may (should) extend the
14
 *   @link MediaInternetBaseHandler MediaInternetBaseHandler @endlink class.
15
 *   Each provider info array may have the following keys:
16
 *   - title: (required) A name to be used when listing the currently supported
17
 *     providers on the web tab of the media browser.
18
 *   - hidden: (optional) Boolean to prevent the provider title from being
19
 *     listed on the web tab of the media browser.
20
 *   - weight: (optional) Integer to determine the tab order. Defaults to 0.
21
 *
22
 * @see hook_media_internet_providers_alter()
23
 * @see media_internet_get_providers()
17 24
 */
18 25
function hook_media_internet_providers() {
19 26
  return array(
20
    'youtube' => array(
21
      'title' => 'youtube',
22
      'image' => 'youtube.jpg',
27
    'MyModuleYouTubeHandler' => array(
28
      'title' => t('YouTube'),
29
      'hidden' => TRUE,
23 30
    ),
24 31
  );
25 32
}
33

  
34
/**
35
 * Alter the list of Internet media providers.
36
 *
37
 * @param array $providers
38
 *   The associative array of Internet media provider definitions from
39
 *   hook_media_internet_providers().
40
 *
41
 * @see hook_media_internet_providers()
42
 * @see media_internet_get_providers()
43
 */
44
function hook_media_internet_providers_alter(&$providers) {
45
  $providers['MyModuleYouTubeHandler']['title'] = t('Google video hosting');
46
  $providers['MyModuleYouTubeHandler']['weight'] = 42;
47
}
drupal7/sites/all/modules/media/modules/media_internet/media_internet.info
12 12
files[] = includes/MediaInternetValidationException.inc
13 13
files[] = tests/media_internet.test
14 14

  
15
; Information added by Drupal.org packaging script on 2014-10-04
16
version = "7.x-2.0-alpha4"
15
; Information added by Drupal.org packaging script on 2015-07-14
16
version = "7.x-2.0-beta1"
17 17
core = "7.x"
18 18
project = "media"
19
datestamp = "1412422430"
19
datestamp = "1436895542"
20 20

  
drupal7/sites/all/modules/media/modules/media_internet/media_internet.module
61 61
}
62 62

  
63 63
/**
64
 * Gets the list of providers.
64
 * Gets the list of Internet media providers.
65 65
 *
66
 * A "Provider" is a bit of meta-data like a title and a logo and a class which
67
 * can handle saving remote files.  Each provider is able to parse an embed code or URL
68
 * and store it as a file object in file_managed.
66
 * Each 'Provider' has a title and a class which can handle saving remote files.
67
 * Providers are each given a turn at parsing a user-submitted URL or embed code
68
 * and, if they recognize that it belongs to a service or protocol they support,
69
 * they store a representation of it as a file object in file_managed.
70
 *
71
 * @return array
72
 *   An associative array of provider information keyed by provider name.
69 73
 */
70 74
function media_internet_get_providers() {
71 75
  $providers = &drupal_static(__FUNCTION__);
72 76

  
73 77
  if (!isset($providers)) {
74
    $cid = 'media:internet:providers';
75
    if ($cache = cache_get($cid)) {
76
      $providers = $cache->data;
77
    }
78
    else {
79
      $providers = array();
80
      foreach (module_implements('media_internet_providers') as $module) {
81
        foreach (module_invoke($module, 'media_internet_providers') as $key => $provider) {
82
          // Store the module here too for convinience.
83
          $providers[$key] = $provider;
84
          $providers[$key]['module'] = $module;
85
          if (!isset($providers[$key]['weight'])) {
86
            $providers[$key]['weight'] = 0;
87
          }
78
    foreach (module_implements('media_internet_providers') as $module) {
79
      foreach (module_invoke($module, 'media_internet_providers') as $class => $info) {
80
        $providers[$class] = $info;
81

  
82
        // Store the name of the module which declared the provider.
83
        $providers[$class]['module'] = $module;
84

  
85
        // Assign a default value to providers which don't specify a weight.
86
        if (!isset($providers[$class]['weight'])) {
87
          $providers[$class]['weight'] = 0;
88 88
        }
89 89
      }
90
      uasort($providers, 'drupal_sort_weight');
91
      cache_set($cid, $providers);
92 90
    }
91

  
92
    // Allow modules to alter the list of providers.
93
    drupal_alter('media_internet_providers', $providers);
94

  
95
    // Sort the providers by weight.
96
    uasort($providers, 'drupal_sort_weight');
93 97
  }
94 98

  
95 99
  return $providers;
......
201 205
      $form['embed_code']['#title'] = t('File URL or media resource');
202 206
      $form['embed_code']['#description'] = t('Enter a URL to a file or media resource. Many media providers also support identifying media via the embed code used to embed the media into external websites.');
203 207

  
204
      $form['embed_code']['#description'] = theme('media_internet_embed_help', array('description' => $form['embed_code']['#description'], 'supported_providers' => implode(' ', $providers)));
208
      $form['embed_code']['#description'] = theme('media_internet_embed_help', array('description' => $form['embed_code']['#description'], 'supported_providers' => implode(', ', $providers)));
205 209
    }
206 210

  
207 211
    $form['#validators'] = array();
drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet.test
21 21
    parent::setUp($modules);
22 22
  }
23 23

  
24
  /**
25
   * Retrieves a sample file of the specified type.
26
   */
27
  function getTestFile($type_name, $size = NULL) {
28
    // Get a file to upload.
29
    $file = current($this->drupalGetTestFiles($type_name, $size));
30

  
31
    // Add a filesize property to files as would be read by file_load().
32
    $file->filesize = filesize($file->uri);
33

  
34
    return $file;
35
  }
36

  
37
  /**
38
   * Retrieves the fid of the last inserted file.
39
   */
40
  function getLastFileId() {
41
    return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField();
42
  }
43

  
24 44
  /**
25 45
   * Get a file from the database based on its filename.
26 46
   *
......
38 58
    $returned_file = reset($files);
39 59
    return $returned_file;
40 60
  }
61

  
62
  protected function createFileType($overrides = array()) {
63
    $type = new stdClass();
64
    $type->type = 'test';
65
    $type->label = "Test";
66
    $type->description = '';
67
    $type->mimetypes = array('image/jpeg', 'image/gif', 'image/png', 'image/tiff');
68

  
69
    foreach ($overrides as $k => $v) {
70
      $type->$k = $v;
71
    }
72

  
73
    file_type_save($type);
74
    return $type;
75
  }
41 76
}
42 77

  
43 78
/**
......
49 84
      'name' => 'Media browser web tab test',
50 85
      'description' => 'Tests the media browser web tab.',
51 86
      'group' => 'Media Internet',
52
      'dependencies' => array('fake'), // @todo remove when File Entity > alpha3 is released. This test currently fails on drupal.org due to testbot dependency issues.
53 87
    );
54 88
  }
55 89

  
......
83 117
}
84 118

  
85 119
/**
86
 * Test file creation through the file upload wizard with remote media.
120
 * Test the default MediaInternetFileHandler provider.
87 121
 */
88
class MediaInternetCreationTestCase extends MediaInternetTestHelper {
122
class MediaInternetRemoteFileTestCase extends MediaInternetTestHelper {
89 123
  public static function getInfo() {
90 124
    return array(
91
      'name' => 'Remote media file creation',
92
      'description' => 'Test file creation with remote media.',
125
      'name' => 'Remote media file handler provider',
126
      'description' => 'Test the default remote file handler provider.',
93 127
      'group' => 'Media Internet',
94
      'dependencies' => array('fake'), // @todo remove when File Entity > alpha3 is released. This test currently fails on drupal.org due to testbot dependency issues.
95 128
    );
96 129
  }
97 130

  
98 131
  function setUp() {
99 132
    parent::setUp();
100 133

  
101
    $web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources', 'edit own document files'));
134
    // Disable the private file system which is automatically enabled by
135
    // DrupalTestCase so we can test the upload wizard correctly.
136
    variable_del('file_private_path');
137

  
138
    $web_user = $this->drupalCreateUser(array('create files', 'add media from remote sources'));
102 139
    $this->drupalLogin($web_user);
103 140
  }
104 141

  
105 142
  /**
106
   * Tests file creation with remote media.
143
   * Tests the default remote file handler.
107 144
   */
108
  function testRemoteMediaFileCreation() {
109
    // Create a file.
145
  function testRemoteFileHandling() {
146
    // Step 1: Add a basic document file by providing a URL to the file.
110 147
    $edit = array();
111 148
    $edit['embed_code'] = file_create_url('README.txt');
112 149
    $this->drupalPost('file/add/web', $edit, t('Next'));
113 150

  
114
    // Step 2: Scheme selection
115
    if ($this->xpath('//input[@name="scheme"]')) {
116
      $this->drupalPost(NULL, array(), t('Next'));
117
    }
118

  
119
    // Check that the document file has been uploaded.
120
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Document', '%name' => 'README.txt')), t('Document file uploaded.'));
121

  
122 151
    // Check that the file exists in the database.
123
    $file = $this->getFileByFilename('README.txt');
152
    $fid = $this->getLastFileId();
153
    $file = file_load($fid);
124 154
    $this->assertTrue($file, t('File found in database.'));
155

  
156
    // Check that the video file has been uploaded.
157
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Document', '%name' => $file->filename)), t('Document file uploaded.'));
125 158
  }
126 159
}
127 160

  
......
134 167
      'name' => 'Custom media provider test',
135 168
      'description' => 'Tests the custom media provider APIs.',
136 169
      'group' => 'Media Internet',
137
      'dependencies' => array('fake'), // @todo remove when File Entity > alpha3 is released. This test currently fails on drupal.org due to testbot dependency issues.
138 170
    );
139 171
  }
140 172

  
141 173
  function setUp() {
142 174
    parent::setUp('media_internet_test');
143 175

  
144
    $web_user = $this->drupalCreateUser(array('access media browser', 'create files', 'add media from remote sources', 'edit own video files'));
176
    // Disable the private file system which is automatically enabled by
177
    // DrupalTestCase so we can test the upload wizard correctly.
178
    variable_del('file_private_path');
179

  
180
    // Enable media_internet_test.module's hook_media_internet_providers()
181
    // implementation.
182
    variable_set('media_internet_test_media_internet_providers', TRUE);
183

  
184
    $web_user = $this->drupalCreateUser(array('create files', 'view own private files', 'add media from remote sources'));
145 185
    $this->drupalLogin($web_user);
146 186
  }
147 187

  
148 188
  /**
149
   * Tests file creation with a custom media provider.
189
   * Test the basic file upload wizard functionality.
150 190
   */
151
  function testFilesBrowserSort() {
191
  function testMediaInternetCustomProviderWizardBasic() {
152 192
    $this->drupalGet('file/add/web');
153 193
    $this->assertResponse(200);
154 194

  
155 195
    // Check that the provider is listed as supported.
156
    $supported_providers = 'Media Internet Test';
157
    $this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . $supported_providers . '</strong>')), t('The example media provider is enabled.'));
196
    $this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . 'Media Internet Test' . '</strong>')), t('The example media provider is enabled.'));
158 197

  
159
    // Create a file.
198
    // Enable media_internet_test.module's
199
    // hook_media_browser_plugin_info_alter_alter() implementation and ensure it
200
    // is working as designed.
201
    variable_set('media_internet_test_media_internet_providers_alter', TRUE);
202

  
203
    $this->drupalGet('file/add/web');
204
    $this->assertRaw(t('Supported internet media providers: !providers.', array('!providers' => '<strong>' . 'Altered provider title' . '</strong>')), t('The example media provider was successfully altered.'));
205

  
206
    // Step 1: Upload a basic video file.
160 207
    $edit = array();
161 208
    $edit['embed_code'] = 'http://www.example.com/video/123';
162 209
    $this->drupalPost('file/add/web', $edit, t('Next'));
163 210

  
164
    // Step 2: Scheme selection
165
    if ($this->xpath('//input[@name="scheme"]')) {
166
      $this->drupalPost(NULL, array(), t('Next'));
167
    }
211
    // Check that the file exists in the database.
212
    $fid = $this->getLastFileId();
213
    $file = file_load($fid);
214
    $this->assertTrue($file, t('File found in database.'));
215

  
216
    // Check that the video file has been uploaded.
217
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => $file->filename)), t('Video file uploaded.'));
218
  }
219

  
220
  /**
221
   * Test the file upload wizard type step.
222
   */
223
  function testMediaInternetCustomProviderWizardTypes() {
224
    // Create multiple file types with the same mime types.
225
    $this->createFileType(array('type' => 'video1', 'label' => 'Video 1', 'mimetypes' => array('video/mediainternettest')));
226
    $this->createFileType(array('type' => 'video2', 'label' => 'Video 2', 'mimetypes' => array('video/mediainternettest')));
227

  
228
    // Step 1: Upload a basic video file.
229
    $edit = array();
230
    $edit['embed_code'] = 'http://www.example.com/video/123';
231
    $this->drupalPost('file/add/web', $edit, t('Next'));
232

  
233
    // Step 2: File type selection.
234
    $edit = array();
235
    $edit['type'] = 'video2';
236
    $this->drupalPost(NULL, $edit, t('Next'));
237

  
238
    // Check that the file exists in the database.
239
    $fid = $this->getLastFileId();
240
    $file = file_load($fid);
241
    $this->assertTrue($file, t('File found in database.'));
242

  
243
    // Check that the video file has been uploaded.
244
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video 2', '%name' => $file->filename)), t('Video 2 file uploaded.'));
245
  }
246

  
247
  /**
248
   * Test the file upload wizard scheme step.
249
   */
250
  function testMediaInternetCustomProviderWizardSchemes() {
251
    // Enable the private file system.
252
    variable_set('file_private_path', $this->private_files_directory);
253

  
254
    // Step 1: Upload a basic video file.
255
    $edit = array();
256
    $edit['embed_code'] = 'http://www.example.com/video/123';
257
    $this->drupalPost('file/add/web', $edit, t('Next'));
258

  
259
    // Step 3: Users should not be able to select a scheme for files with
260
    // read-only stream wrappers.
261
    $this->assertNoFieldByName('scheme');
262

  
263
    // Check that the file exists in the database.
264
    $fid = $this->getLastFileId();
265
    $file = file_load($fid);
266
    $this->assertTrue($file, t('File found in database.'));
168 267

  
169 268
    // Check that the video file has been uploaded.
170
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => 'Drupal')), t('Video file uploaded.'));
269
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => $file->filename)), t('Video file uploaded.'));
270
  }
271

  
272
  /**
273
   * Test the file upload wizard field step.
274
   */
275
  function testMediaInternetCustomProviderWizardFields() {
276
    $filename = $this->randomName();
277

  
278
    // Add a text field to the video file type.
279
    $field_name = drupal_strtolower($this->randomName() . '_field_name');
280
    $field = array('field_name' => $field_name, 'type' => 'text');
281
    field_create_field($field);
282
    $instance = array(
283
      'field_name' => $field_name,
284
      'entity_type' => 'file',
285
      'bundle' => 'video',
286
      'label' => $this->randomName() . '_label',
287
    );
288
    field_create_instance($instance);
289

  
290
    // Step 1: Upload a basic video file.
291
    $edit = array();
292
    $edit['embed_code'] = 'http://www.example.com/video/123';
293
    $this->drupalPost('file/add/web', $edit, t('Next'));
294

  
295
    // Step 4: Attached fields.
296
    $edit = array();
297
    $edit['filename'] = $filename;
298
    $edit[$field_name . '[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
299
    $this->drupalPost(NULL, $edit, t('Save'));
171 300

  
172 301
    // Check that the file exists in the database.
173
    $file = $this->getFileByFilename('Drupal');
302
    $fid = $this->getLastFileId();
303
    $file = file_load($fid);
174 304
    $this->assertTrue($file, t('File found in database.'));
305

  
306
    // Check that the video file has been uploaded.
307
    $this->assertRaw(t('!type %name was uploaded.', array('!type' => 'Video', '%name' => $filename)), t('Video file uploaded.'));
308
  }
309

  
310
  /**
311
   * Test skipping each of the file upload wizard steps.
312
   */
313
  function testMediaInternetCustomProviderWizardStepSkipping() {
314
    $filename = $this->randomName();
315

  
316
    // Ensure that the file is affected by every step.
317
    variable_set('file_private_path', $this->private_files_directory);
318

  
319
    $this->createFileType(array('type' => 'video1', 'label' => 'Video 1', 'mimetypes' => array('video/mediainternettest')));
320
    $this->createFileType(array('type' => 'video2', 'label' => 'Video 2', 'mimetypes' => array('video/mediainternettest')));
321

  
322
    $field_name = drupal_strtolower($this->randomName() . '_field_name');
323
    $field = array('field_name' => $field_name, 'type' => 'text');
324
    field_create_field($field);
325
    $instance = array(
326
      'field_name' => $field_name,
327
      'entity_type' => 'file',
328
      'bundle' => 'video2',
329
      'label' => $this->randomName() . '_label',
330
    );
331
    field_create_instance($instance);
332

  
333
    // Test skipping each upload wizard step.
334
    foreach (array('types', 'schemes', 'fields') as $step) {
335
      // Step to skip.
336
      switch ($step) {
337
        case 'types':
338
          variable_set('file_entity_file_upload_wizard_skip_file_type', TRUE);
339
          break;
340
        case 'schemes':
341
          variable_set('file_entity_file_upload_wizard_skip_scheme', TRUE);
342
          break;
343
        case 'fields':
344
          variable_set('file_entity_file_upload_wizard_skip_fields', TRUE);
345
          break;
346
      }
347

  
348
      // Step 1: Upload a basic video file.
349
      $edit = array();
350
      $edit['embed_code'] = 'http://www.example.com/video/123';
351
      $this->drupalPost('file/add/web', $edit, t('Next'));
352

  
353
      // Step 2: File type selection.
354
      if ($step != 'types') {
355
        $edit = array();
356
        $edit['type'] = 'video2';
357
        $this->drupalPost(NULL, $edit, t('Next'));
358
      }
359

  
360
      // Step 3: Users should not be able to select a scheme for files with
361
      // read-only stream wrappers.
362
      $this->assertNoFieldByName('scheme');
363

  
364
      // Step 4: Attached fields.
365
      if ($step != 'fields') {
366
        // Skipping file type selection essentially skips this step as well
367
        // because the file will not be assigned a type so no fields will be
368
        // available.
369
        if ($step != 'types') {
370
          $edit = array();
371
          $edit['filename'] = $filename;
372
          $edit[$field_name . '[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName();
373
          $this->drupalPost(NULL, $edit, t('Save'));
374
        }
375
      }
376

  
377
      // Check that the file exists in the database.
378
      $fid = $this->getLastFileId();
379
      $file = file_load($fid);
380
      $this->assertTrue($file, t('File found in database.'));
381

  
382
      // Determine the file's file type.
383
      $type = file_type_load($file->type);
384

  
385
      // Check that the video file has been uploaded.
386
      $this->assertRaw(t('!type %name was uploaded.', array('!type' => $type->label, '%name' => $file->filename)), t('Video file uploaded.'));
387

  
388
      // Reset 'skip' variables.
389
      variable_del('file_entity_file_upload_wizard_skip_file_type');
390
      variable_del('file_entity_file_upload_wizard_skip_scheme');
391
      variable_del('file_entity_file_upload_wizard_skip_fields');
392
    }
175 393
  }
176 394
}
drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet_test.info
7 7
files[] = includes/MediaInternetTestStreamWrapper.inc
8 8
files[] = includes/MediaInternetTestHandler.inc
9 9

  
10
; Information added by Drupal.org packaging script on 2014-10-04
11
version = "7.x-2.0-alpha4"
10
; Information added by Drupal.org packaging script on 2015-07-14
11
version = "7.x-2.0-beta1"
12 12
core = "7.x"
13 13
project = "media"
14
datestamp = "1412422430"
14
datestamp = "1436895542"
15 15

  
drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet_test.module
9 9
 * Implements hook_media_internet_providers().
10 10
 */
11 11
function media_internet_test_media_internet_providers() {
12
  // Allow tests to enable or disable this hook.
13
  if (!variable_get('media_internet_test_media_internet_providers', FALSE)) {
14
    return array();
15
  }
16

  
12 17
  return array(
13 18
    'MediaInternetTestHandler' => array(
14 19
      'title' => t('Media Internet Test'),
......
16 21
  );
17 22
}
18 23

  
24
/**
25
 * Implements hook_media_browser_plugin_info_alter_alter().
26
 */
27
function media_internet_test_media_internet_providers_alter(&$providers) {
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff