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_all_day/date_all_day.module
31 31
        'format' => NULL,
32 32
        'entity_type' => NULL,
33 33
        'entity' => NULL,
34
        'view' => NULL
35
      )
34
        'view' => NULL,
35
      ),
36 36
    ),
37 37
    'date_all_day_label' => array(
38
       'variables' => array()
38
      'variables' => array(),
39 39
    ),
40 40
  );
41 41

  
......
91 91
/**
92 92
 * Adjust start/end date format to account for 'all day' .
93 93
 *
94
 * @param array $field, the field definition for this date field.
95
 * @param string $which, which value to return, 'date1' or 'date2' .
96
 * @param object $date1, a date/time object for the 'start' date.
97
 * @param object $date2, a date/time object for the 'end' date.
98
 * @param string $format
99
 * @param object $entity, the node this date comes from (may be incomplete, always contains nid).
100
 * @param object $view, the view this node comes from, if applicable.
101
 * @return formatted date.
94
 * @params array $field
95
 *   The field definition for this date field.
96
 *
97
 * @params string $which
98
 *   Which value to return, 'date1' or 'date2'.
99
 *
100
 * @params object $date1
101
 *   A date/time object for the 'start' date.
102
 *
103
 * @params object $date2
104
 *   A date/time object for the 'end' date.
105
 *
106
 * @params string $format
107
 *   A date/time format
108
 *
109
 * @params object $entity
110
 *   The node this date comes from (may be incomplete, always contains nid).
111
 *
112
 * @params object $view
113
 *   The view this node comes from, if applicable.
114
 *
115
 * @return string
116
 *   Formatted date.
102 117
 */
103 118
function theme_date_all_day($vars) {
104 119
  $field    = $vars['field'];
......
135 150
  }
136 151

  
137 152
  return trim(date_format_date($$which, 'custom', $format) . $suffix);
138

  
139 153
}
140 154

  
141 155
/**
142 156
 * Theme the way an 'all day' label will look.
143 157
 */
144 158
function theme_date_all_day_label() {
145
  return '(' . t('All day', array(), array('context' => 'datetime')) .')';
159
  return '(' . t('All day', array(), array('context' => 'datetime')) . ')';
146 160
}
147 161

  
148 162
/**
149 163
 * Determine if a Start/End date combination qualify as 'All day'.
150 164
 *
151
 * @param array $field, the field definition for this date field.
152
 * @param object $date1, a date/time object for the 'Start' date.
153
 * @param object $date2, a date/time object for the 'End' date.
154
 * @return TRUE or FALSE.
165
 * @param array $field
166
 *   The field definition for this date field.
167
 *
168
 * @param array $instance
169
 *   The field instance for this date field.
170
 *
171
 * @param object $date1
172
 *   A date/time object for the 'Start' date.
173
 *
174
 * @param object $date2
175
 *   A date/time object for the 'End' date.
176
 *
177
 * @return bool
178
 *   TRUE or FALSE.
155 179
 */
156 180
function date_all_day_field($field, $instance, $date1, $date2 = NULL) {
157 181
  if (empty($date1) || !is_object($date1)) {
......
167 191
  $granularity = date_granularity_precision($field['settings']['granularity']);
168 192
  $increment = isset($instance['widget']['settings']['increment']) ? $instance['widget']['settings']['increment'] : 1;
169 193
  return date_is_all_day(date_format($date1, DATE_FORMAT_DATETIME), date_format($date2, DATE_FORMAT_DATETIME), $granularity, $increment);
170

  
171 194
}
172 195

  
173 196
/**
......
222 245
function date_all_day_date_text_process_alter(&$element, &$form_state, $context) {
223 246
  $all_day_id = !empty($element['#date_all_day_id']) ? $element['#date_all_day_id'] : '';
224 247
  if ($all_day_id != '') {
225
    // All Day handling on text dates works only if the user leaves the time out of the input value.
248
    // All Day handling on text dates works only
249
    // if the user leaves the time out of the input value.
226 250
    // There is no element to hide or show.
227 251
  }
228 252
}
......
234 258
 */
235 259
function date_all_day_date_select_process_alter(&$element, &$form_state, $context) {
236 260

  
237
  // Hide or show this element in reaction to the all_day status for this element.
261
  // Hide or show this element in reaction
262
  // to the all_day status for this element.
238 263
  $all_day_id = !empty($element['#date_all_day_id']) ? $element['#date_all_day_id'] : '';
239 264
  if ($all_day_id != '') {
240
    foreach(array('hour', 'minute', 'second', 'ampm') as $field) {
265
    foreach (array('hour', 'minute', 'second', 'ampm') as $field) {
241 266
      if (array_key_exists($field, $element)) {
242 267
        $element[$field]['#states'] = array(
243 268
          'visible' => array(
......
255 280
 */
256 281
function date_all_day_date_popup_process_alter(&$element, &$form_state, $context) {
257 282

  
258
  // Hide or show this element in reaction to the all_day status for this element.
283
  // Hide or show this element in reaction to
284
  // the all_day status for this element.
259 285
  $all_day_id = !empty($element['#date_all_day_id']) ? $element['#date_all_day_id'] : '';
260 286
  if ($all_day_id != '' && array_key_exists('time', $element)) {
261 287
    $element['time']['#states'] = array(
......
272 298
 * of the date_select validation gets fired.
273 299
 */
274 300
function date_all_day_date_text_pre_validate_alter(&$element, &$form_state, &$input) {
275
  // Let Date module massage the format for all day values so they will pass validation.
301
  // Let Date module massage the format for all day
302
  // values so they will pass validation.
276 303
  // The All day flag, if used, actually exists on the parent element.
277 304
  date_all_day_value($element, $form_state);
278 305
}
......
284 311
 * of the date_select validation gets fired.
285 312
 */
286 313
function date_all_day_date_select_pre_validate_alter(&$element, &$form_state, &$input) {
287
  // Let Date module massage the format for all day values so they will pass validation.
314
  // Let Date module massage the format for all
315
  // day values so they will pass validation.
288 316
  // The All day flag, if used, actually exists on the parent element.
289 317
  date_all_day_value($element, $form_state);
290 318
}
......
296 324
 * of the date_popup validation gets fired.
297 325
 */
298 326
function date_all_day_date_popup_pre_validate_alter(&$element, &$form_state, &$input) {
299
  // Let Date module massage the format for all day values so they will pass validation.
327
  // Let Date module massage the format for all
328
  // day values so they will pass validation.
300 329
  // The All day flag, if used, actually exists on the parent element.
301 330
  date_all_day_value($element, $form_state);
302 331
}
303 332

  
304 333
/**
305
 * A helper function to check if the all day flag is set on the parent of an
334
 * A helper function date_all_day_value().
335
 *
336
 * To check if the all day flag is set on the parent of an
306 337
 * element, and adjust the date_format accordingly so the missing time will
307 338
 * not cause validation errors.
308 339
 */
......
332 363
    $field = $context['field'];
333 364

  
334 365
    // If we have an all day flag on this date and the time is empty,
335
    // change the format to match the input value so we don't get validation errors.
366
    // change the format to match the input value
367
    // so we don't get validation errors.
336 368
    $element['#date_is_all_day'] = TRUE;
337 369
    $element['value']['#date_format'] = date_part_format('date', $element['value']['#date_format']);
338 370
    if (!empty($field['settings']['todate'])) {
......
344 376
/**
345 377
 * Implements hook_date_combo_validate_date_start_alter().
346 378
 *
347
 * This hook lets us alter the local date objects created by the date_combo validation
348
 * before they are converted back to the database timezone and stored.
379
 * This hook lets us alter the local date objects
380
 * created by the date_combo validation before they are
381
 * converted back to the database timezone and stored.
349 382
 */
350 383
function date_all_day_date_combo_validate_date_start_alter(&$date, &$form_state, $context) {
351

  
352
   // If this is an 'All day' value, set the time to midnight.
353
   if (!empty($context['element']['#date_is_all_day'])) {
354
     $date->setTime(0, 0, 0);
355
   }
384
  // If this is an 'All day' value, set the time to midnight.
385
  if (!empty($context['element']['#date_is_all_day'])) {
386
    $date->setTime(0, 0, 0);
387
  }
356 388
}
357 389

  
358 390
/**
359 391
 * Implements hook_date_combo_validate_date_end_alter().
360 392
 *
361
 * This hook lets us alter the local date objects created by the date_combo validation
362
 * before they are converted back to the database timezone and stored.
393
 * This hook lets us alter the local date objects
394
 * created by the date_combo validation before
395
 * they are converted back to the database timezone and stored.
363 396
 */
364 397
function date_all_day_date_combo_validate_date_end_alter(&$date, &$form_state, $context) {
365

  
366
   // If this is an 'All day' value, set the time to midnight.
367
   if (!empty($context['element']['#date_is_all_day'])) {
368
     $date->setTime(0, 0, 0);
369
   }
398
  // If this is an 'All day' value, set the time to midnight.
399
  if (!empty($context['element']['#date_is_all_day'])) {
400
    $date->setTime(0, 0, 0);
401
  }
370 402
}
371 403

  
372 404
/**

Formats disponibles : Unified diff