Projet

Général

Profil

Révision 1e39edcb

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/includes/media_wysiwyg.pages.inc
97 97
    $form['options']['fields'][$field_name]['#access'] = $allow;
98 98
  }
99 99

  
100
  // Add view mode preview.
101
  media_wysiwyg_format_form_view_mode($form, $form_state, $file);
102

  
100 103
  // Similar to a form_alter, but we want this to run first so that
101 104
  // media.types.inc can add the fields specific to a given type (like alt tags
102 105
  // on media). If implemented as an alter, this might not happen, making other
......
110 113

  
111 114
  return $form;
112 115
}
116

  
117
/**
118
 * Add ajax preview when selecting view mode in wysiwyg editor.
119
 */
120
function media_wysiwyg_format_form_view_mode(&$form, $form_state, $file)  {
121
  // Check to see if a view mode ("format") has already been specified for
122
  //  this media item. First, check for a standard form-submitted value.
123
  if (!empty($form_state['values']['format'])) {
124
    $view_mode = $form_state['values']['format'];
125
  }
126
  // Second, check the request for a JSON-encoded value.
127
  elseif (isset($_GET['fields'])) {
128
    $query_fields = drupal_json_decode($_GET['fields']);
129
    if (isset($query_fields['format'])) {
130
      $view_mode = $query_fields['format'];
131
    }
132
  }
133
  // If we were unable to determine a view mode, or we found a view mode
134
  //  that does not exist in the list of format options presented on this
135
  //  form, use the default view mode.
136
  if (!isset($view_mode) || !array_key_exists($view_mode, $form['options']['format']['#options'])) {
137
    $view_mode = variable_get('media_wysiwyg_wysiwyg_default_view_mode', 'full');
138
  }
139

  
140
  $form['preview'] = array();
141
  $form['preview']['#prefix'] = '<div class="media-item"><div class="media-thumbnail">';
142
  $form['preview']['#suffix'] = '</div><div class="label-wrapper"><label class="media-filename">' . $file->filename . '</label></div></div>';
143
  $form['preview']['thumbnail'] = file_view_file($file, $view_mode);
144
  $form['preview']['thumbnail']['#prefix'] = '<div id="media-preview">';
145
  $form['preview']['thumbnail']['#suffix'] = '</div>';
146

  
147
  if (!isset($form['options']['format']['#default_value'])) {
148
    $form['options']['format']['#default_value'] = $view_mode;
149
  }
150
  $form['options']['format']['#ajax'] = array(
151
    'callback' => 'media_wysiwyg_format_form_preview',
152
    'wrapper' => 'media-preview',
153
  );
154

  
155
  $wysiwyg_view_mode = db_query('SELECT view_mode FROM {media_view_mode_wysiwyg} WHERE type = :type', array(':type' => $file->type))->fetchField();
156
  $view_modes = media_wysiwyg_get_wysiwyg_allowed_view_modes($file);
157
  $formats = $options = array();
158

  
159
  foreach ($view_modes as $view_mode => $view_mode_info) {
160
    $options[$view_mode] = $view_mode_info['label'];
161

  
162
    if (!empty($wysiwyg_view_mode)) {
163
      $element = media_wysiwyg_get_file_without_label($file, $wysiwyg_view_mode, array('wysiwyg' => TRUE));
164
    }
165
    else {
166
      $element = media_wysiwyg_get_file_without_label($file, $view_mode, array('wysiwyg' => TRUE));
167
    }
168

  
169
    $formats[$view_mode] = drupal_render($element);
170
  }
171

  
172
  $form['#formats'] = $formats;
173
  $form['options']['format']['#options'] = $options;
174
}
175

  
176
/**
177
 * AJAX callback to select the portion of the format form to be updated with a preview.
178
 *
179
 * @param array $form
180
 *   An associative array containing the structure of the form.
181
 * @param array $form_state
182
 *   An associative array containing the current state of the form.
183
 *
184
 * @return array
185
 *   The preview form item.
186
 */
187
function media_wysiwyg_format_form_preview($form, $form_state) {
188
  return $form['preview']['thumbnail'];
189
}

Formats disponibles : Unified diff