Projet

Général

Profil

Révision da542b7b

Ajouté par Assos Assos il y a plus de 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.module
148 148
  return $element;
149 149
}
150 150

  
151
/**
152
 * Implements hook_form_FORM_ID_alter().
153
 */
154
function media_wysiwyg_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
155
  // Add a checkbox that marks this field as one that can be
156
  // overridden in the WYSIWYG.
157
  if ($form['#instance']['entity_type'] == 'file') {
158
    $field_type = $form['#field']['type'];
159
    $allowed_field_types = variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long'));
160
    if (in_array($field_type, $allowed_field_types)) {
161
      $form['instance']['settings']['wysiwyg_override'] = array(
162
        '#type' => 'checkbox',
163
        '#title' => t('Override in WYSIWYG'),
164
        '#description' => t('If checked, then this field may be overridden in the WYSIWYG editor.'),
165
        '#default_value' => isset($form['#instance']['settings']['wysiwyg_override']) ? $form['#instance']['settings']['wysiwyg_override'] : FALSE,
166
      );
167
    }
168
  }
169
}
170

  
151 171
/**
152 172
 * Implements hook_form_FORM_ID_alter().
153 173
 */
......
234 254
    '#default_value' => variable_get('media_wysiwyg_wysiwyg_allowed_types', array('audio', 'image', 'video', 'document')),
235 255
  );
236 256

  
257
  $options = array();
258
  foreach(field_info_field_types() as $key => $type) {
259
    $options[$key] = $type['label'];
260
  }
261
  asort($options);
262
  $form['wysiwyg']['media_wysiwyg_wysiwyg_override_field_types'] = array(
263
    '#type' => 'checkboxes',
264
    '#title' => t('Override field types in WYSIWYG'),
265
    '#options' => $options,
266
    '#default_value' => variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long')),
267
    '#description' => t('If checked, then the field type may be overridden in the WYSIWYG editor. Not all field types (e.g. Term reference) currently support being overridden so the desired result might not be achieved.')
268
  );
269

  
237 270
  $form['#submit'][] = 'media_wysiwyg_admin_config_browser_pre_submit';
238 271
}
239 272

  
......
261 294
    'tips callback' => 'media_filter_tips',
262 295
  );
263 296

  
297
  $filters['media_filter_paragraph_fix'] = array(
298
    'title' => t('Ensure that embedded Media tags are not contained in paragraphs'),
299
    'description' => t('This filter will strip any paragraph tags surrounding embedded Media tags. This helps to avoid the chopped up markup that can result from unexpectedly closed paragraph tags. This filter should be positioned above (before) the "Convert Media tags to markup" filter.'),
300
    'process callback' => 'media_wysiwyg_filter_paragraph_fix',
301
    'weight' => 1,
302
  );
303

  
264 304
  return $filters;
265 305
}
266 306

  
......
308 348
 * Optional custom settings can override how the file is displayed.
309 349
 */
310 350
function media_wysiwyg_get_file_without_label($file, $view_mode, $settings = array(), $langcode = NULL) {
351
  // Get the override alt & title from the fields override array. Grab the
352
  // "special" field names from the token replacement in file_entity, then see
353
  // if an override is provided and needed.
354
  $pattern = '/\[(\w+):(\w+)\]/';
355
  $alt = variable_get('file_entity_alt', '[file:field_file_image_alt_text]');
356
  $title = variable_get('file_entity_title', '[file:field_file_image_title_text]');
357
  $overrides = array(
358
    'alt' => $alt,
359
    'title' => $title,
360
  );
361
  foreach ($overrides as $field_type => $field_name) {
362
    preg_match($pattern, $field_name, $matches);
363
    if (!empty($matches[2])) {
364
      $field_name = $matches[2];
365
      $langcode = field_language('file', $file, $field_name);
366
      if (isset($settings['fields'][$field_name][$langcode]['value'])) {
367
        if (empty($settings['attributes'][$field_type])) {
368
          $settings['attributes'][$field_type] = $settings['fields'][$field_name][$langcode]['value'];
369
        }
370
      }
371
      if (isset($settings['fields'][$field_name][$langcode][0]['value'])) {
372
        if (empty($settings['attributes'][$field_type])) {
373
          $settings['attributes'][$field_type] = $settings['fields'][$field_name][$langcode][0]['value'];
374
        }
375
      }
376
    }
377
  }
378

  
311 379
  $file->override = $settings;
312 380

  
313 381
  $element = file_view_file($file, $view_mode, $langcode);
......
447 515
  drupal_alter('media_wysiwyg_wysiwyg_allowed_view_modes', $view_modes, $file);
448 516
  return $view_modes;
449 517
}
518

  
519
/**
520
 * Implements hook_file_displays_alter().
521
 */
522
function media_wysiwyg_file_displays_alter(&$displays, $file, $view_mode) {
523
  // Override the fields of the file when requested by the WYSIWYG.
524
  if (isset($file->override) && isset($file->override['fields'])) {
525
    $instance = field_info_instances('file', $file->type);
526
    foreach ($file->override['fields'] as $field_name => $value) {
527
      if (!isset($instance[$field_name]['settings']) || !isset($instance[$field_name]['settings']['wysiwyg_override']) || $instance[$field_name]['settings']['wysiwyg_override']) {
528
        $file->{$field_name} = $value;
529
      }
530
    }
531
  }
532
}

Formats disponibles : Unified diff