Projet

Général

Profil

Révision 02a0babc

Ajouté par Assos Assos il y a presque 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/file_entity/file_entity.pages.inc
85 85
  }
86 86
  $step = (isset($form_state['step']) && in_array($form_state['step'], array(1, 2, 3, 4))) ? $form_state['step'] : 1;
87 87
  $form['#step'] = $step;
88
  $form['#options'] = $options;
88
  $form['#options'] = $options + array(
89
    'types' => array(),
90
    'enabledPlugins' => array(),
91
    'schemes' => array(),
92
    'max_filesize' => '',
93
    'uri_scheme' => 'public',
94
    'plugins' => ''
95
  );
96

  
89 97
  switch ($step) {
90 98
    case 1:
91 99
      return file_entity_add_upload_step_upload($form, $form_state, $options);
......
133 141
 */
134 142
function file_entity_add_upload_step_filetype($form, &$form_state, array $options = array()) {
135 143
  $file = file_load($form_state['storage']['upload']);
144
  $selected_files = $form['#options']['types'];
136 145

  
137 146
  $form['type'] = array(
138 147
    '#type' => 'radios',
139 148
    '#title' => t('File type'),
140
    '#options' => file_entity_get_filetype_candidates($file),
149
    '#options' => file_entity_get_filetype_candidates($file, $selected_files),
141 150
    '#default_value' => isset($form_state['storage']['type']) ? $form_state['storage']['type'] : NULL,
142 151
    '#required' => TRUE,
143 152
  );
......
312 321
 * @return array
313 322
 *   An array of file type bundles that support the file's mime type.
314 323
 */
315
function file_entity_get_filetype_candidates($file) {
324
function file_entity_get_filetype_candidates($file, $selected_files = array()) {
316 325
  $types = module_invoke_all('file_type', $file);
317 326
  drupal_alter('file_type', $types, $file);
327

  
328
  // If no file types are selected in field instance settings, allow all
329
  // available types.
330
  if (!empty($selected_files)) {
331
    // Limit file type candidates to field allowed types.
332
    $types = array_intersect($types, $selected_files);
333
  }
334

  
318 335
  $candidates = array();
319 336
  foreach ($types as $type) {
320 337
    $file->type = $type;
......
332 349
  $form_state['storage'] = isset($form_state['storage']) ? $form_state['storage'] : array();
333 350
  $form_state['storage'] = array_merge($form_state['storage'], $form_state['values']);
334 351

  
352
  // Field selected allowed types.
353
  $selected_files = $form['#options']['types'];
354

  
335 355
  // This var is set to TRUE when we are ready to save the file.
336 356
  $save = FALSE;
337 357
  $trigger = $form_state['triggering_element']['#id'];
......
349 369
      $file = file_load($form_state['storage']['upload']);
350 370
      if ($step == 2) {
351 371
        // Check if we can skip step 2.
352
        $candidates = file_entity_get_filetype_candidates($file);
372
        $candidates = file_entity_get_filetype_candidates($file, $selected_files);
353 373
        if (count($candidates) == 1) {
354 374
          $candidates_keys = array_keys($candidates);
355 375
          // There is only one possible filetype for this file.
......
853 873
  if (file_uri_scheme($file->uri) != $form_state['values']['scheme']) {
854 874
    $file_destination = $form_state['values']['scheme'] . '://' . file_uri_target($file->uri);
855 875
    $file_destination = file_stream_wrapper_uri_normalize($file_destination);
876
    $file_destination_dirname = drupal_dirname($file_destination);
877
    // Create the directory in case it doesn't exist.
878
    file_prepare_directory($file_destination_dirname, FILE_CREATE_DIRECTORY);
856 879
    if ($moved_file = file_move($file, $file_destination, FILE_EXISTS_RENAME)) {
857 880
      // Only re-assign the file object if file_move() did not fail.
858 881
      $file = $moved_file;

Formats disponibles : Unified diff