Révision 599a39cd
Ajouté par Assos Assos il y a environ 3 ans
drupal7/sites/all/modules/date/date.module | ||
---|---|---|
20 | 20 |
|
21 | 21 |
default: |
22 | 22 |
$bundle = field_extract_bundle($entity_type, $entity); |
23 |
break; |
|
24 | 23 |
} |
24 |
|
|
25 | 25 |
// If there is no bundle name, field_info() uses the entity name as the bundle |
26 | 26 |
// name in its arrays. |
27 | 27 |
if (empty($bundle)) { |
... | ... | |
157 | 157 |
/** |
158 | 158 |
* Implements hook_element_info(). |
159 | 159 |
* |
160 |
* date_combo will create a 'start' and optional 'end' date, along with
|
|
160 |
* Date_combo will create a 'start' and optional 'end' date, along with
|
|
161 | 161 |
* an optional 'timezone' column for date-specific timezones. Each |
162 | 162 |
* 'start' and 'end' date will be constructed from date_select or date_text. |
163 | 163 |
*/ |
... | ... | |
170 | 170 |
'#process' => array('date_combo_element_process'), |
171 | 171 |
'#element_validate' => array('date_combo_validate'), |
172 | 172 |
'#theme_wrappers' => array('date_combo'), |
173 |
'#attached' => array('css' => array( |
|
174 |
drupal_get_path('module', 'date_api') . '/date.css', |
|
175 |
)), |
|
173 | 176 |
); |
174 | 177 |
if (module_exists('ctools')) { |
175 | 178 |
$type['date_combo']['#pre_render'] = array('ctools_dependent_pre_render'); |
... | ... | |
185 | 188 |
* @param string $formatter |
186 | 189 |
* The date formatter. |
187 | 190 |
* @param string $entity_type |
188 |
* The entity_type for the instance |
|
191 |
* The entity_type for the instance.
|
|
189 | 192 |
* @param object $entity |
190 | 193 |
* The entity object. |
191 | 194 |
* @param array $field |
... | ... | |
215 | 218 |
* ) |
216 | 219 |
* ) |
217 | 220 |
*/ |
218 |
function date_formatter_process($formatter, $entity_type, $entity, $field, $instance, $langcode, $item, $display) {
|
|
221 |
function date_formatter_process($formatter, $entity_type, $entity, array $field, array $instance, $langcode, array $item, array $display) {
|
|
219 | 222 |
$dates = array(); |
220 | 223 |
$timezone = date_default_timezone(); |
221 | 224 |
if (empty($timezone)) { |
... | ... | |
338 | 341 |
* $field['settings']['granularity'] will contain an array like |
339 | 342 |
* ('hour' => 'hour', 'month' => 0) where the values turned on return their own |
340 | 343 |
* names and the values turned off return a zero need to reconfigure this into |
341 |
* simple array of the turned on values |
|
344 |
* simple array of the turned on values.
|
|
342 | 345 |
* |
343 | 346 |
* @param array $field |
344 | 347 |
* The field array. |
345 | 348 |
*/ |
346 |
function date_granularity($field) { |
|
349 |
function date_granularity(array $field) {
|
|
347 | 350 |
if (!is_array($field) || !is_array($field['settings']['granularity'])) { |
348 | 351 |
$granularity = drupal_map_assoc(array('year', 'month', 'day')); |
349 | 352 |
$field['settings']['granularity'] = $granularity; |
... | ... | |
352 | 355 |
} |
353 | 356 |
|
354 | 357 |
/** |
355 |
* Helper function to create an array of the date values in a field that need to be processed. |
|
358 |
* Create an array of the date values in a field that need to be processed. |
|
359 |
* |
|
360 |
* @param array $field |
|
361 |
* The field being processed. |
|
362 |
* |
|
363 |
* @return array |
|
364 |
* The date values which need to be processed. |
|
356 | 365 |
*/ |
357 |
function date_process_values($field) { |
|
366 |
function date_process_values(array $field) {
|
|
358 | 367 |
return $field['settings']['todate'] ? array('value', 'value2') : array('value'); |
359 | 368 |
} |
360 | 369 |
|
... | ... | |
449 | 458 |
else { |
450 | 459 |
$format = date_format_type_format($format_type, $langcode); |
451 | 460 |
} |
452 |
break; |
|
453 | 461 |
} |
454 | 462 |
|
455 | 463 |
// A selected format might include timezone information. |
... | ... | |
471 | 479 |
// we receive (due to inconsistency of core api) an array of all (other) |
472 | 480 |
// formats available for $langcode in locale table. |
473 | 481 |
// However there's no guarantee that the key $format_type exists. |
474 |
// See http://drupal.org/node/1302358.
|
|
482 |
// @see http://drupal.org/node/1302358
|
|
475 | 483 |
if (!is_string($format)) { |
476 | 484 |
// If the configuration page at admin/config/regional/date-time was |
477 | 485 |
// never saved, the default core date format variables |
... | ... | |
493 | 501 |
case 'medium': |
494 | 502 |
default: |
495 | 503 |
// @todo: If a non-core module provides a date type and does not |
496 |
// variable_set() a default for it, the default assumed here may |
|
497 |
// not be correct (since the default format used by 'medium' may
|
|
498 |
// not even be one of the allowed formats for the date type in
|
|
499 |
// question). To fix this properly, we should really call
|
|
500 |
// system_get_date_formats($format_type) and take the first |
|
501 |
// format from that list as the default. However, this function
|
|
502 |
// is called often (on many different page requests), so calling
|
|
504 |
// variable_set() a default for it, the default assumed here may not
|
|
505 |
// be correct (since the default format used by 'medium' may not even
|
|
506 |
// be one of the allowed formats for the date type in question). To
|
|
507 |
// fix this properly, we should really call |
|
508 |
// system_get_date_formats($format_type) and take the first format
|
|
509 |
// from that list as the default. However, this function is called
|
|
510 |
// often (on many different page requests), so calling |
|
503 | 511 |
// system_get_date_formats() from here would be a performance hit |
504 |
// since that function writes several records to the database |
|
505 |
// during each page request that calls it.
|
|
512 |
// since that function writes several records to the database during
|
|
513 |
// each page request that calls it. |
|
506 | 514 |
$default = 'D, m/d/Y - H:i'; |
507 |
break; |
|
508 |
|
|
509 | 515 |
} |
510 | 516 |
$format = variable_get('date_format_' . $format_type, $default); |
511 | 517 |
} |
... | ... | |
656 | 662 |
return NULL; |
657 | 663 |
} |
658 | 664 |
|
659 |
$timezone_db = !empty($item['timezone_db']) ? $item['timezone_db'] : 'UTC';
|
|
665 |
$timezone_db = date_get_timezone_db($info['field']['settings']['tz_handling']);
|
|
660 | 666 |
$date = new DateObject($value, $timezone_db); |
661 | 667 |
return !empty($date) ? date_format_date($date, 'custom', 'U') : NULL; |
662 | 668 |
} |
... | ... | |
714 | 720 |
* |
715 | 721 |
* Based on entity_property_verbatim_set(). |
716 | 722 |
* |
717 |
* The passed in unix timestamp (UTC) is converted to the right value and format dependent on the field. |
|
723 |
* The passed in unix timestamp (UTC) is converted to the right value and format |
|
724 |
* dependent on the field. |
|
718 | 725 |
* |
719 | 726 |
* $name is either 'value' or 'value2'. |
720 | 727 |
*/ |
... | ... | |
736 | 743 |
} |
737 | 744 |
|
738 | 745 |
/** |
739 |
* Duplicate functionality of what is now date_all_day_field() in the Date All Day module.
|
|
746 |
* Duplicate of what is now date_all_day_field() in the Date All Day module. |
|
740 | 747 |
* |
741 |
* Copy left here to avoid breaking other modules that use this function.
|
|
748 |
* Left here to avoid breaking other modules that use this function.
|
|
742 | 749 |
* |
743 |
* DEPRECATED!, will be removed at some time in the future.
|
|
750 |
* DEPRECATED! Will be removed at some time in the future.
|
|
744 | 751 |
*/ |
745 | 752 |
function date_field_all_day($field, $instance, $date1, $date2 = NULL) { |
746 | 753 |
if (empty($date1) || !is_object($date1)) { |
747 | 754 |
return FALSE; |
748 | 755 |
} |
749 | 756 |
elseif (!date_has_time($field['settings']['granularity'])) { |
750 |
return TRUE;
|
|
757 |
return FALSE;
|
|
751 | 758 |
} |
759 |
// The master setting for the 'all day' functionality. |
|
760 |
elseif (empty($instance['settings']['widget']['settings']['display_all_day'])) { |
|
761 |
return FALSE; |
|
762 |
} |
|
763 |
|
|
752 | 764 |
if (empty($date2)) { |
753 | 765 |
$date2 = $date1; |
754 | 766 |
} |
755 | 767 |
|
768 |
// Use central logic for determining the granularity. |
|
756 | 769 |
$granularity = date_granularity_precision($field['settings']['granularity']); |
757 |
$increment = isset($instance['widget']['settings']['increment']) ? $instance['widget']['settings']['increment'] : 1; |
|
770 |
|
|
771 |
// The increment is 1 by default, but it can be overridden. |
|
772 |
$increment = 1; |
|
773 |
if (isset($instance['widget']['settings']['increment'])) { |
|
774 |
$increment = $instance['widget']['settings']['increment']; |
|
775 |
} |
|
776 |
|
|
758 | 777 |
return date_is_all_day(date_format($date1, DATE_FORMAT_DATETIME), date_format($date2, DATE_FORMAT_DATETIME), $granularity, $increment); |
759 | 778 |
} |
760 | 779 |
|
... | ... | |
771 | 790 |
* |
772 | 791 |
* DEPRECATED!, will be removed at some time in the future. |
773 | 792 |
*/ |
774 |
function date_field_get_sql_handler($field, $compare_tz = NULL) { |
|
793 |
function date_field_get_sql_handler(array $field, $compare_tz = NULL) {
|
|
775 | 794 |
module_load_include('inc', 'date_api', 'date_api_sql'); |
776 | 795 |
|
777 | 796 |
$db_info = date_api_database_info($field); |
... | ... | |
802 | 821 |
|
803 | 822 |
/** |
804 | 823 |
* Implements hook_field_widget_properties_alter(). |
805 |
* |
|
806 |
* Alters the widget properties of a field instance before it gets displayed. |
|
807 |
* Used here to flag new entities so we can later tell if they need default values. |
|
808 | 824 |
*/ |
809 |
function date_field_widget_properties_alter(&$widget, $context) { |
|
825 |
function date_field_widget_properties_alter(array &$widget, $context) { |
|
826 |
// Alters the widget properties of a field instance before it gets displayed. |
|
827 |
// Used here to flag new entities so we can later tell if they need default |
|
828 |
// values. |
|
810 | 829 |
if (in_array($widget['type'], array('date_select', 'date_text', 'date_popup'))) { |
811 | 830 |
$entity_type = $context['entity_type']; |
812 | 831 |
$entity = $context['entity']; |
... | ... | |
818 | 837 |
} |
819 | 838 |
} |
820 | 839 |
} |
840 |
|
|
841 |
/** |
|
842 |
* Implements hook_migrate_api(). |
|
843 |
*/ |
|
844 |
function date_migrate_api() { |
|
845 |
$api = array( |
|
846 |
'api' => 2, |
|
847 |
'field handlers' => array('DateMigrateFieldHandler'), |
|
848 |
); |
|
849 |
return $api; |
|
850 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules