Projet

Général

Profil

Révision 2b3c8cc1

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

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;

Formats disponibles : Unified diff