Projet

Général

Profil

Révision 29771811

Ajouté par Assos Assos il y a presque 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/media/includes/media.fields.inc
2 2

  
3 3
/**
4 4
 * @file
5
 * Provide the media selector widget and media field formatters to the Fields
6
 * API.
5
 * Provide media selector widget and media field formatters to the fields API.
7 6
 */
8 7

  
9 8
/**
......
137 136
  elseif (module_exists('translation') && $element['#entity_type'] == 'node' && translation_supported_type($element['#entity']->type)) {
138 137
    $element['#media_parent_entity_form_langcode'] = $element['#entity']->language;
139 138
    $element['#media_parent_entity_source_langcode'] = $element['#entity']->language;
140
  } elseif ($element['#entity_type'] == 'field_collection_item' && !empty($form['#entity']) && property_exists($form['#entity'], 'language')) {
139
  }
140
  elseif ($element['#entity_type'] == 'field_collection_item' && !empty($form['#entity']) && property_exists($form['#entity'], 'language')) {
141 141
    $element['#media_parent_entity_form_langcode'] = $form['#entity']->language;
142 142
  }
143
  else if ($element['#entity_type'] == 'paragraphs_item' && !empty($form['#entity'])) {
143
  elseif ($element['#entity_type'] == 'paragraphs_item' && !empty($form['#entity'])) {
144 144
    $host = $element['#entity']->hostEntity();
145 145
    if (isset($host->language)) {
146 146
      $element['#media_parent_entity_form_langcode'] = $host->language;
......
271 271
    );
272 272
  }
273 273

  
274
  // Add the alt field if enabled.
275
  if (!empty($instance['settings']['alt_field']) && $item['fid']) {
276
    $element['alt'] = array(
277
      '#title' => t('Alternate text'),
278
      '#type' => 'textfield',
279
      '#default_value' => isset($item['alt']) ? $item['alt'] : '',
280
      '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.<br />
281
<em>(Notice: this field is not fetched on -all- formatters yet. For example: If the Rendered file formatter will be used, this field is not available at the moment.)</em>'),
282
      '#maxlength' => variable_get('image_alt_length', 80),
283
      '#weight' => 1,
284
    );
285
  }
286

  
287
  // Add the title field if enabled.
288
  if (!empty($instance['settings']['title_field']) && $item['fid']) {
289
    $element['title'] = array(
290
      '#type' => 'textfield',
291
      '#title' => t('Title'),
292
      '#default_value' => isset($item['title']) ? $item['title'] : '',
293
      '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.<br />
294
<em>(Notice: this field is not fetched on -all- formatters yet. For example: If the Rendered file formatter will be used, this field is not available at the moment.)</em>'),
295
      '#maxlength' => variable_get('image_title_length', 500),
296
      '#weight' => 2,
297
    );
298
  }
299

  
274 300
  // Adjust the Ajax settings so that on upload and remove of any individual
275 301
  // file, the entire group of file fields is updated together.
276 302
  if ($field['cardinality'] != 1) {
......
306 332
 * wrapper around the entire group so it can be replaced all at once.
307 333
 */
308 334
function media_field_widget_process_multiple($element, &$form_state, $form) {
309
    // In order to support multiple selection, we need to reconstruct the _POST
335
  // In order to support multiple selection, we need to reconstruct the _POST
310 336
  // data that is checked in media_attach_file(). We need to reconstruct the
311 337
  // field's _POST key name, for example: field_mediafield_und_0.
312 338
  $upload_name_prefix = implode('_', $element['#parents']) . '_';
......
314 340
  if (!empty($_POST['media'][$upload_name])) {
315 341
    $files = explode(',', $_POST['media'][$upload_name]);
316 342
    $count = count($files);
317
    // Supposing #file_upload_delta is always the last delta this will work
343
    // Supposing #file_upload_delta is always the last delta this will work.
318 344
    for ($i = 0; $i < $count; $i++) {
319 345
      // For each file selected, increment the field key to be processed.
320 346
      // field_mediafield_und_0 becomes field_mediafield_und_1, etc.
......
366 392
 *
367 393
 * This helper function is used by media_field_widget_process_multiple().
368 394
 *
369
 * @param $element
395
 * @param array $element
370 396
 *   The element being processed.
371 397
 *
372 398
 * @return
......
386 412
}
387 413

  
388 414
/**
389
 * Form submission handler for attach/remove button of media_field_widget_form().
415
 * Form submit handler for attach/remove button of media_field_widget_form().
390 416
 *
391 417
 * This runs in addition to and after media_field_widget_submit().
392 418
 *
......
434 460
/**
435 461
 * Returns HTML for an individual media widget.
436 462
 *
437
 * @param $variables
463
 * @param array $variables
438 464
 *   An associative array containing:
439 465
 *   - element: A render element representing the widget.
440 466
 *
......
467 493
/**
468 494
 * Returns HTML for a group of media widgets.
469 495
 *
470
 * @param $variables
496
 * @param array $variables
471 497
 *   An associative array containing:
472 498
 *   - element: A render element representing the widgets.
473 499
 *
......
561 587
    );
562 588
  }
563 589

  
564
  $table = array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => $table_id));
590
  $table = array(
591
    'header' => $headers,
592
    'rows' => $rows,
593
    'attributes' => array('id' => $table_id)
594
  );
565 595

  
566 596
  drupal_alter('media_widget_multiple', $table, $element);
567 597

  
......
623 653
 * Implements hook_field_formatter_settings_form().
624 654
 *
625 655
 * Legacy support for the "Large filetype icon" file field formatter.
656
 *
626 657
 * @see media_field_formatter_info()
627 658
 */
628 659
function media_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
......
645 676
 * Implements hook_field_formatter_settings_summary().
646 677
 *
647 678
 * Legacy support for the "Large filetype icon" file field formatter.
679
 *
648 680
 * @see media_field_formatter_info()
649 681
 */
650 682
function media_field_formatter_settings_summary($field, $instance, $view_mode) {
......
672 704
 * Implements hook_field_formatter_view().
673 705
 *
674 706
 * Legacy support for the "Large filetype icon" file field formatter.
707
 *
675 708
 * @see media_field_formatter_info()
676 709
 */
677 710
function media_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {

Formats disponibles : Unified diff