Projet

Général

Profil

Révision b720ea3e

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

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/date/date_elements.inc
40 40
 *
41 41
 * - In the field's submission processing, the new date values, which are in
42 42
 *   the local timezone, are converted back to their UTC values and stored.
43
 *
44 43
 */
45 44
function date_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
46 45

  
......
87 86
  }
88 87

  
89 88
  module_load_include('inc', 'date_api', 'date_api_elements');
90
  $timezone = date_get_timezone($field['settings']['tz_handling'], isset($items[0]['timezone']) ? $items[0]['timezone'] : date_default_timezone());
89
  $timezone = date_get_timezone($field['settings']['tz_handling'], isset($items[$delta]['timezone']) ? $items[$delta]['timezone'] : date_default_timezone());
91 90

  
92 91
  // TODO see if there's a way to keep the timezone element from ever being
93 92
  // nested as array('timezone' => 'timezone' => value)). After struggling
......
122 121
      '#weight' => $instance['widget']['weight'] + 1,
123 122
      '#attributes' => array('class' => array('date-no-float')),
124 123
      '#date_label_position' => $instance['widget']['settings']['label_position'],
125
      );
124
    );
125
  }
126

  
127
  // Make changes if instance is set to be rendered as a regular field.
128
  if (!empty($instance['widget']['settings']['no_fieldset'])) {
129
   $element['#title'] = check_plain($instance['label']);
130
   $element['#theme_wrappers'] = ($field['cardinality'] == 1) ? array('date_form_element') : array();
126 131
  }
127 132

  
128 133
  return $element;
......
148 153
  // @TODO Figure out how to replace date_fuzzy_datetime() function.
149 154
  // Special case for ISO dates to create a valid date object for formatting.
150 155
  // Is this still needed?
156
  // @codingStandardsIgnoreStart
151 157
  /*
152 158
  if ($field['type'] == DATE_ISO) {
153 159
    $value = date_fuzzy_datetime($value);
......
157 163
    $value = date_convert($value, $field['type'], DATE_DATETIME, $db_timezone);
158 164
  }
159 165
  */
166
  // @codingStandardsIgnoreEnd
160 167

  
161 168
  $date = new DateObject($value, date_get_timezone_db($field['settings']['tz_handling']));
162 169
  $date->limitGranularity($field['settings']['granularity']);
......
193 200
}
194 201

  
195 202
/**
196
 * Helper function for the date default value callback to set
197
 * either 'value' or 'value2' to its default value.
203
 * Helper function for the date default value callback to set either 'value' or 'value2' to its default value.
198 204
 */
199 205
function date_default_value_part($item, $field, $instance, $langcode, $part = 'value') {
200 206
  $timezone = date_get_timezone($field['settings']['tz_handling']);
......
241 247
 * Process an individual date element.
242 248
 */
243 249
function date_combo_element_process($element, &$form_state, $form) {
244
    
245 250
  if (date_hidden_element($element)) {
246 251
    // A hidden value for a new entity that had its end date set to blank
247 252
    // will not get processed later to populate the end date, so set it here.
......
296 301
  // Blank out the end date for optional end dates that match the start date,
297 302
  // except when this is a new node that has default values that should be honored.
298 303
  if (!$date_is_default && $field['settings']['todate'] != 'required'
304
  && is_array($element['#default_value'])
299 305
  && !empty($element['#default_value'][$to_field])
300 306
  && $element['#default_value'][$to_field] == $element['#default_value'][$from_field]) {
301 307
    unset($element['#default_value'][$to_field]);
......
329 335
    '#date_increment'   => $instance['widget']['settings']['increment'],
330 336
    '#date_year_range'  => $instance['widget']['settings']['year_range'],
331 337
    '#date_label_position' => $instance['widget']['settings']['label_position'],
332
    );
338
  );
333 339

  
334
  $description =  !empty($element['#description']) ? t($element['#description']) : '';
340
  $description = !empty($element['#description']) ? t($element['#description']) : '';
335 341
  unset($element['#description']);
336 342

  
337 343
  // Give this element the right type, using a Date API
......
347 353
      $element['#attached']['js'][] = drupal_get_path('module', 'date') . '/date.js';
348 354
      $element[$from_field]['#ajax'] = !empty($element['#ajax']) ? $element['#ajax'] : FALSE;
349 355
      break;
356

  
350 357
    case 'date_popup':
351 358
      $element[$from_field]['#type'] = 'date_popup';
352 359
      $element[$from_field]['#theme_wrappers'] = array('date_popup');
353 360
      $element[$from_field]['#ajax'] = !empty($element['#ajax']) ? $element['#ajax'] : FALSE;
354 361
      break;
362

  
355 363
    default:
356 364
      $element[$from_field]['#type'] = 'date_text';
357 365
      $element[$from_field]['#theme_wrappers'] = array('date_text');
......
380 388
    if ($field['settings']['todate'] == 'optional') {
381 389
      $element[$to_field]['#states'] = array(
382 390
        'visible' => array(
383
          'input[name="' . $show_id . '"]' => array('checked' => TRUE),
384
      ));
391
          'input[name="' . $show_id . '"]' => array(
392
            'checked' => TRUE,
393
          ),
394
        ),
395
      );
385 396
    }
386 397
  }
387 398
  else {
......
404 415
    $element[$from_field]['#date_title'] = t('@field_name', array('@field_name' => $instance['label']));
405 416
  }
406 417

  
418
  // Make changes if instance is set to be rendered as a regular field.
419
  if (!empty($instance['widget']['settings']['no_fieldset'])) {
420
    unset($element[$from_field]['#description']);
421
    if (!empty($field['settings']['todate']) && isset($element['#description'])) {
422
      $element['#description'] .= '<span class="js-hide"> ' . t("Empty 'End date' values will use the 'Start date' values.") . '</span>';
423
    }
424
  }
425

  
407 426
  $context = array(
408
   'field' => $field,
409
   'instance' => $instance,
410
   'form' => $form,
427
    'field'     => $field,
428
    'instance'  => $instance,
429
    'form'      => $form,
411 430
  );
412 431
  drupal_alter('date_combo_process', $element, $form_state, $context);
413 432

  
414 433
  return $element;
415 434
}
416 435

  
436
/**
437
 * Empty a date element.
438
 */
417 439
function date_element_empty($element, &$form_state) {
418 440
  $item = array();
419 441
  $item['value'] = NULL;
......
428 450

  
429 451
/**
430 452
 * Validate and update a combo element.
453
 *
431 454
 * Don't try this if there were errors before reaching this point.
432 455
 */
433 456
function date_combo_validate($element, &$form_state) {
......
444 467
  $delta = $element['#delta'];
445 468
  $langcode = $element['#language'];
446 469

  
470
  // Related issue: https://drupal.org/node/2279831.
471
  if (!is_array($element['#field_parents'])) {
472
    $element['#field_parents'] = array();
473
  }
447 474
  $form_values = drupal_array_get_nested_value($form_state['values'], $element['#field_parents']);
448 475
  $form_input = drupal_array_get_nested_value($form_state['input'], $element['#field_parents']);
449 476

  

Formats disponibles : Unified diff