Projet

Général

Profil

Révision ee46a8ed

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

Update date 7.x-2.9 -> 7.x-2.10-rc1

Voir les différences:

date/CHANGELOG.txt
1
Date Module 8.x
2
=================
date/LICENSE.txt
1
                    GNU GENERAL PUBLIC LICENSE
2
                       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
                            Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Lesser General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

  
59
                    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

  
114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

  
172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

  
229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
                            NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
                     END OF TERMS AND CONDITIONS
281

  
282
            How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
287

  
288
  To do so, attach the following notices to the program.  It is safest
289
to attach them to the start of each source file to most effectively
290
convey the exclusion of warranty; and each file should have at least
291
the "copyright" line and a pointer to where the full notice is found.
292

  
293
    <one line to give the program's name and a brief idea of what it does.>
294
    Copyright (C) <year>  <name of author>
295

  
296
    This program is free software; you can redistribute it and/or modify
297
    it under the terms of the GNU General Public License as published by
298
    the Free Software Foundation; either version 2 of the License, or
299
    (at your option) any later version.
300

  
301
    This program is distributed in the hope that it will be useful,
302
    but WITHOUT ANY WARRANTY; without even the implied warranty of
303
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304
    GNU General Public License for more details.
305

  
306
    You should have received a copy of the GNU General Public License along
307
    with this program; if not, write to the Free Software Foundation, Inc.,
308
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309

  
310
Also add information on how to contact you by electronic and paper mail.
311

  
312
If the program is interactive, make it output a short notice like this
313
when it starts in an interactive mode:
314

  
315
    Gnomovision version 69, Copyright (C) year name of author
316
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
    This is free software, and you are welcome to redistribute it
318
    under certain conditions; type `show c' for details.
319

  
320
The hypothetical commands `show w' and `show c' should show the appropriate
321
parts of the General Public License.  Of course, the commands you use may
322
be called something other than `show w' and `show c'; they could even be
323
mouse-clicks or menu items--whatever suits your program.
324

  
325
You should also get your employer (if you work as a programmer) or your
326
school, if any, to sign a "copyright disclaimer" for the program, if
327
necessary.  Here is a sample; alter the names:
328

  
329
  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
  `Gnomovision' (which makes passes at compilers) written by James Hacker.
331

  
332
  <signature of Ty Coon>, 1 April 1989
333
  Ty Coon, President of Vice
334

  
335
This General Public License does not permit incorporating your program into
336
proprietary programs.  If your program is a subroutine library, you may
337
consider it more useful to permit linking proprietary applications with the
338
library.  If this is what you want to do, use the GNU Lesser General
339
Public License instead of this License.
date/README.txt
1
INFORMATION FOR DEVELOPERS
2

  
3
Once the Date API is installed, all functions in the API are available to be
4
used anywhere by any module.
5

  
6
The API uses the PHP 5.3 date functions to create and manipulate dates.
7

  
8
A component class is available, new DrupalDateTime($string, $timezone, $format), where
9
$string is a unixtimestamp, an ISO date, a string like YYYY-MM-DD HH:MM:SS,
10
or an array of date parts like 'year', 'month', 'day', 'hour', 'minute',
11
$timezone is the name of the timezone this date is in, and $format is the format
12
of date it is (DATE_FORMAT_UNIX, DATE_FORMAT_ISO, or DATE_FORMAT_DATETIME). It
13
creates and return a date object set to the right date and timezone.
14

  
15
Simpletest tests for these functions are included in the package.
16

  
17
Available functions include the following (more documentation is provided in
18
the files):
19

  
20
============================================================================
21
Preconfigured arrays
22
============================================================================
23
Both translated and untranslated values are available. The
24
$calendar->week_days_ordered() function will shift an array of week day names so it
25
starts with the site's first day of the week, otherwise the weekday names start
26
with Sunday as the first value, which is the expected order for many php and sql
27
functions.
28

  
29
$calendar = system_calendar();
30
$calendar->month_names();
31
$calendar->month_names_abbr();
32
$calendar->month_names();
33
$calendar->week_days();
34
$calendar->week_days_abbr();
35
$calendar->week_days();
36
$calendar->week_days_ordered();
37
$calendar->years();
38
$calendar->hours();
39
$calendar->minutes();
40
$calendar->seconds();
41
$calendar->ampm();
42

  
43
============================================================================
44
Date calculation and navigation
45
============================================================================
46
date_difference() will find the time difference between any two days, measured
47
in seconds, minutes, hours, days, months, weeks, or years.
48

  
49
$calendar->days_in_month();
50
$calendar->days_in_year();
51
date_calendar_weeks_in_year();
52
$calendar->day_of_week();
53
$calendar->day_of_week_name();
54

  
55
============================================================================
56
Date regex and format helpers
57
============================================================================
58
Pre-defined constants, an array of date format strings and their
59
equivalent regex strings.
60

  
61
DATE_REGEX_LOOSE is a very loose regex that will pull date parts out
62
of an ISO date with or without separators, using either 'T' or a space
63
to separate date and time, and with or without time.
64

  
65
DATE_FORMAT_ISO
66
DATE_FORMAT_DATETIME
67
DATE_FORMAT_UNIX
68
DATE_FORMAT_ICAL
69

  
70
DATE_REGEX_ISO
71
DATE_REGEX_DATETIME
72
DATE_REGEX_LOOSE
73

  
74
date_short_formats();
75
date_medium_formats();
76
date_long_formats();
77
date_format_patterns();
78

  
79
============================================================================
80
Standardized ical parser and creator
81
============================================================================
82
The iCal parser is Drupal/date_api/DateiCalParse. Use that class to
83
manipulate iCal strings.
84

  
85
The class parses the ical into an array that can be used
86
in various ways. It no longer trys to convert timezones while parsing,
87
instead a date_ical_date_format() function is provided that can be used to
88
convert from the ical timezone to whatever timezone is desired in the
89
results. Repeat rules are parsed into an array which other modules can
90
manipulate however they like to create additional events from the results.
91

  
92
date_ical_export();
93
date_ical_import();
94
date_ical_date_format();
95

  
96
============================================================================
97
Helpers for portable date SQL
98
============================================================================
99
The SQL functions are found in date_api_sql.inc, which is not included by
100
default. Include that file if you want to use these functions:
101

  
102
date_sql();
103
date_server_zone_adj();
104
date_sql_concat();
105
date_sql_pad();
106

  
107
============================================================================
108
Date forms and validators
109
============================================================================
110
Reusable, configurable, self-validating FAPI date elements are found in
111
date_api_elements.inc, which is not included by default. Include it
112
if you want to use these elements. To use them, create a form element
113
and set the '#type' to one of the following:
114

  
115
date_select
116
 The date_select element will create a collection of form elements, with a
117
 separate select or textfield for each date part. The whole collection will
118
 get reformatted back into a date value of the requested type during validation.
119

  
120
date_text
121
 The date_text element will create a textfield that can contain a whole
122
 date or any part of a date as text. The user input value will be re-formatted
123
 back into a date value of the requested type during validation.
124

  
125
date_timezone
126
 The date_timezone element will create a drop-down selector to pick a
127
 timezone name.
128

  
129
The custom date elements require a few other pieces of information to work
130
correctly, like #date_format and #date_type. See the internal documentation
131
for more information.
132

  
133
============================================================================
134
Date Popup Module
135
============================================================================
136

  
137
A new module is included in the package that will enable a popup jQuery
138
calendar date picker and timepicker in date and time fields.
139

  
140
It is implemented as a custom form element, so set '#type' to 'date_popup'
141
to use this element. See the internal documentation for more information.
142

  
143
============================================================================
144
Date Repeat API
145
============================================================================
146

  
147
An API for repeating dates is available if installed. It can be used by
148
other modules to create a form element that will allow users to select
149
repeat rules and store those selections in an iCal RRULE string, and a
150
calculation function that will parse the RRULE and return an array of dates
151
that match those rules. The API is implemented in the Date module as a
152
new date widget if the Date Repeat API is installed.
153

  
154
============================================================================
155
RDF Integration
156
============================================================================
157

  
158
To make RDF easier to use, the base date themes (date_display_single and
159
date_display_range) have been expanded so they pass attributes and
160
RDF mappings for the field, if any, to the theme. If RDF is installed
161
and no other mappings are provided, the theme adds RDF information
162
to mark both the Start and End dates as 'xsd:dateTime' datatypes with the
163
property of 'dc:date'. This occurs in the theme preprocess layer, in
164
particular via the functions template_preprocess_date_display_single() and
165
template_preprocess_date_display_range().
166

  
167
To mark these as events instead, you could install the schemaorg
168
module, which will load the schema.org vocabulary. The mark the content type
169
that contains events as an 'Event', using the UI exposed by that
170
module and set the event start date field with the 'dateStart'
171
property and tag other fields in the content type with the appropriate
172
property types. The Date module theme will wrap the start and end
173
date output with appropriate markup.
174

  
175
If the result is not quite what you need, you should be able to implement your
176
own theme preprocess functions, e.g. MYTHEME_preprocess_date_display_single()
177
or MYTHEME_preprocess_date_display_range() and alter the attributes to use the
178
values you want.
date/date.api.php
1
<?php
2

  
3
/**
4
 * @file
5
 * Hooks provided by the Date module.
6
 */
7

  
8
use Drupal\date_api\DateGranularity;
9
use Drupal\Core\Datetime\DrupalDateTime;
10

  
11
/**
12
 * Alter the default value for a date argument.
13
 *
14
 * @param object $argument
15
 *   The argument object.
16
 * @param string $value
17
 *   The default value created by the argument handler.
18
 */
19
function hook_date_default_argument_alter(&$argument, &$value) {
20
  $style_options = $style_options = $argument->view->display_handler->get_option('style_options');
21
  if (!empty($style_options['track_date'])) {
22
    $default_date = new DrupalDateTime();
23
    $value = $default_date->format($argument->arg_format);
24
  }
25
}
26

  
27
/**
28
 * Alter the entity before formatting it.
29
 *
30
 * @param object $entity
31
 *   The entity object being viewed.
32
 * @param array $variables
33
 *   The variables passed to the formatter.
34
 *   - entity: The $entity object.
35
 *   - entity_type: The $entity_type.
36
 *   - field: The $field array.
37
 *   - instance: The $instance array.
38
 *   - langcode: The $langcode.
39
 *   - items: The $items array.
40
 *   - display: The $display array.
41
 *   - dates: The processed dates array, empty at this point.
42
 *   - attributes: The attributes array, empty at this point.
43
 *   - rdf_mapping: The RDF mapping array.
44
 *   - add_rdf: If module_exists('rdf').
45
 */
46
function hook_date_formatter_pre_view_alter(&$entity, &$variables) {
47
  if (!empty($entity->view)) {
48
    $field = $variables['field'];
49
    $date_id = 'date_id_' . $field['field_name'];
50
    $date_delta = 'date_delta_' . $field['field_name'];
51
    $date_item = $entity->view->result[$entity->view->row_index];
52
    if (!empty($date_item->$date_id)) {
53
      $entity->date_id = 'date.' . $date_item->$date_id . '.' . $field['field_name'] . '.' . $date_item->$date_delta . '.0';
54
    }
55
  }
56
}
57

  
58
/**
59
 * Alter the dates array created by date_formatter_process().
60
 *
61
 * @param array $dates
62
 *   The $dates array created by the Date module.
63
 * @param array $context
64
 *   An associative array containing the following keys:
65
 *   - field: The $field array.
66
 *   - instance: The $instance array.
67
 *   - format: The string $format.
68
 *   - entity_type: The $entity_type.
69
 *   - entity: The $entity object.
70
 *   - langcode: The string $langcode.
71
 *   - item: The $item array.
72
 *   - display: The $display array.
73
 */
74
function hook_date_formatter_dates_alter(&$dates, $context) {
75
  $field = $context['field'];
76
  $instance = $context['instance'];
77
  $format = $context['format'];
78
  $entity_type = $context['entity_type'];
79
  $entity = $context['entity'];
80
  $date1 = $dates['value']['local']['object'];
81
  $date2 = $dates['value2']['local']['object'];
82

  
83
  $is_all_day = date_all_day_field($field, $instance, $date1, $date2);
84

  
85
  $all_day1 = '';
86
  $all_day2 = '';
87
  if ($format != 'format_interval' && $is_all_day) {
88
    $all_day1 = theme('date_all_day', array(
89
      'field' => $field,
90
      'instance' => $instance,
91
      'which' => 'date1',
92
      'date1' => $date1,
93
      'date2' => $date2,
94
      'format' => $format,
95
      'entity_type' => $entity_type,
96
      'entity' => $entity));
97
    $all_day2 = theme('date_all_day', array(
98
      'field' => $field,
99
      'instance' => $instance,
100
      'which' => 'date2',
101
      'date1' => $date1,
102
      'date2' => $date2,
103
      'format' => $format,
104
      'entity_type' => $entity_type,
105
      'entity' => $entity));
106
    $dates['value']['formatted_time'] = theme('date_all_day_label');
107
    $dates['value2']['formatted_time'] = theme('date_all_day_label');
108
    $dates['value']['formatted'] = $all_day1;
109
    $dates['value2']['formatted'] = $all_day2;
110
  }
111
}
112

  
113
/**
114
 * Alter the date_select element before the rest of the validation is run.
115
 *
116
 * @param array $element
117
 *   The $element array.
118
 * @param array $form_state
119
 *   A keyed array containing the current state of the form.
120
 * @param array $input
121
 *   The array of input values to be validated.
122
 */
123
function hook_date_select_pre_validate_alter(&$element, &$form_state, &$input) {
124
  // Let Date module massage the format for all day values so they will pass
125
  // validation. The All day flag, if used, actually exists on the parent
126
  // element.
127
  date_all_day_value($element, $form_state);
128
}
129

  
130
/**
131
 * Alter the date_popup element before the rest of the validation is run.
132
 *
133
 * @param array $element
134
 *   The $element array.
135
 * @param array $form_state
136
 *   A keyed array containing the current state of the form.
137
 * @param array $input
138
 *   The array of input values to be validated.
139
 */
140
function hook_date_popup_pre_validate_alter(&$element, &$form_state, &$input) {
141
  // Let Date module massage the format for all day values so they will pass
142
  // validation. The All day flag, if used, actually exists on the parent
143
  // element.
144
  date_all_day_value($element, $form_state);
145
}
146

  
147
/**
148
 * Alter the date_combo element before the rest of the validation is run.
149
 *
150
 * @param array $element
151
 *   The $element array.
152
 * @param array $form_state
153
 *   A keyed array containing the current state of the form.
154
 * @param array $context
155
 *   An associative array containing the following keys:
156
 *   - field: The $field array.
157
 *   - instance: The $instance array.
158
 *   - item: The $item array.
159
 *
160
 * @see date_combo_element_process()
161
 */
162
function hook_date_combo_pre_validate_alter(&$element, &$form_state, $context) {
163
  if (!empty($context['item']['all_day'])) {
164

  
165
    $field = $context['field'];
166

  
167
    // If we have an all day flag on this date and the time is empty, change the
168
    // format to match the input value so we don't get validation errors.
169
    $element['#date_is_all_day'] = TRUE;
170
    $element['value']['#date_date_format'] = date_part_format('date', $element['value']['#date_date_format']);
171
    if (!empty($field['settings']['todate'])) {
172
      $element['value2']['#date_date_format'] = date_part_format('date', $element['value2']['#date_date_format']);
173
    }
174
  }
175
}
176

  
177
/**
178
 * Alter the local start date objects created by the date_combo validation.
179
 *
180
 * This is called before the objects are converted back to the database timezone
181
 * and stored.
182
 *
183
 * @param object $date
184
 *   The $date object.
185
 * @param array $form_state
186
 *   A keyed array containing the current state of the form.
187
 * @param array $context
188
 *   An associative array containing the following keys:
189
 *  - field: The $field array.
190
 *  - instance: The $instance array.
191
 *  - item: The $item array.
192
 *  - element: The $element array.
193
 */
194
function hook_date_combo_validate_date_start_alter(&$date, &$form_state, $context) {
195
  // If this is an 'All day' value, set the time to midnight.
196
  if (!empty($context['element']['#date_is_all_day'])) {
197
    $date->setTime(0, 0, 0);
198
  }
199
}
200

  
201
/**
202
 * Alter the local end date objects created by the date_combo validation.
203
 *
204
 * This is called before the objects are converted back to the database timezone
205
 * and stored.
206
 *
207
 * @param object $date
208
 *   The $date object.
209
 * @param array $form_state
210
 *   A keyed array containing the current state of the form.
211
 * @param array $context
212
 *   An associative array containing the following keys:
213
 *  - field: The $field array.
214
 *  - instance: The $instance array.
215
 *  - item: The $item array.
216
 *  - element: The $element array.
217
 */
218
function hook_date_combo_validate_date_end_alter(&$date, &$form_state, $context) {
219
  // If this is an 'All day' value, set the time to midnight.
220
  if (!empty($context['element']['#date_is_all_day'])) {
221
    $date->setTime(0, 0, 0);
222
  }
223
}
224

  
225
/**
226
 * Alter the date_select widget element.
227
 *
228
 * @param array $element
229
 *   An associative array containing the properties of the date_select element.
230
 * @param array $form_state
231
 *   A keyed array containing the current state of the form.
232
 * @param array $context
233
 *   An associative array containing the following keys:
234
 *   - form: Nested array of form elements that comprise the form.
235
 *
236
 * @see date_select_element_process()
237
 */
238
function hook_date_select_process_alter(&$element, &$form_state, $context) {
239
  // Hide or show the element in reaction to the all_day status for the element.
240
  $all_day_id = !empty($element['#date_all_day_id']) ? $element['#date_all_day_id'] : '';
241
  if ($all_day_id != '') {
242
    foreach (array('hour', 'minute', 'second', 'ampm') as $field) {
243
      if (array_key_exists($field, $element)) {
244
        $element[$field]['#states'] = array(
245
          'visible' => array(
246
            'input[name="' . $all_day_id . '"]' => array('checked' => FALSE),
247
          ),
248
        );
249
      }
250
    }
251
  }
252
}
253

  
254
/**
255
 * Alter the date_popup widget element.
256
 *
257
 * @param array $element
258
 *   An associative array containing the properties of the date_popup element.
259
 * @param array $form_state
260
 *   A keyed array containing the current state of the form.
261
 * @param array $context
262
 *   An associative array containing the following keys:
263
 *   - form: Nested array of form elements that comprise the form.
264
 *
265
 * @see date_popup_element_process()
266
 */
267
function hook_date_popup_process_alter(&$element, &$form_state, $context) {
268
  // Hide or show the element in reaction to the all_day status for the element.
269
  $all_day_id = !empty($element['#date_all_day_id']) ? $element['#date_all_day_id'] : '';
270
  if ($all_day_id != '' && array_key_exists('time', $element)) {
271
    $element['time']['#states'] = array(
272
      'visible' => array(
273
        'input[name="' . $all_day_id . '"]' => array('checked' => FALSE),
274
      ),
275
    );
276
  }
277
}
278

  
279
/**
280
 * Alter the date_combo element after the Date module is finished with it.
281
 *
282
 * @param array $element
283
 *   The $element array.
284
 * @param array $form_state
285
 *   A keyed array containing the current state of the form.
286
 * @param array $context
287
 *   An associative array containing the following keys:
288
 *   - field: The $field array.
289
 *   - instance: The $instance array.
290
 *   - form: Nested array of form elements that comprise the form.
291
 */
292
function hook_date_combo_process_alter(&$element, &$form_state, $context) {
293
  $field = $context['field'];
294
  $instance = $context['instance'];
295
  $field_name = $element['#field_name'];
296
  $delta = $element['#delta'];
297

  
298
  // Add a date repeat form element, if needed.
299
  // We delayed until this point so we don't bother adding it to hidden fields.
300
  if (date_is_repeat_field($field, $instance)) {
301
    $item = $element['#value'];
302
    $element['rrule'] = array(
303
      '#type' => 'date_repeat_rrule',
304
      '#theme_wrappers' => array('date_repeat_rrule'),
305
      '#default_value' => isset($item['rrule']) ? $item['rrule'] : '',
306
      '#date_timezone' => $element['#date_timezone'],
307
      '#date_format'      => DateGranularity::limitFormat(date_input_format($element, $field, $instance), $field['settings']['granularity']),
308
      '#date_text_parts'  => (array) $instance['widget']['settings']['text_parts'],
309
      '#date_increment'   => $instance['widget']['settings']['increment'],
310
      '#date_year_range'  => $instance['widget']['settings']['year_range'],
311
      '#date_label_position' => $instance['widget']['settings']['label_position'],
312
      '#date_repeat_widget' => str_replace('_repeat', '', $instance['widget']['type']),
313
      '#date_flexible' => 0,
314
      '#weight' => $instance['widget']['weight'] + .4,
315
    );
316
  }
317
}
318

  
319
/**
320
 * Alter the date_timezone widget element.
321
 *
322
 * @param array $element
323
 *   An associative array containing the properties of the date_select element.
324
 * @param array $form_state
325
 *   A keyed array containing the current state of the form.
326
 * @param array $context
327
 *   An associative array containing the following keys:
328
 *   - form: Nested array of form elements that comprise the form.
329
 *
330
 * @see date_timezone_element_process()
331
 */
332
function hook_date_timezone_process_alter(&$element, &$form_state, $context) {
333
  // @todo.
334
}
335

  
336
/**
337
 * Alter the date_year_range widget element.
338
 *
339
 * @param array $element
340
 *   An associative array containing the properties of the date_select element.
341
 * @param array $form_state
342
 *   A keyed array containing the current state of the form.
343
 * @param array $context
344
 *   An associative array containing the following keys:
345
 *   - form: Nested array of form elements that comprise the form.
346
 *
347
 * @see date_year_range_element_process()
348
 */
349
function hook_date_year_range_process_alter(&$element, &$form_state, $context) {
350
  // @todo.
351
}
352

  
353
/**
354
 * Alter a date field settings form.
355
 *
356
 * @param array $form
357
 *   Nested array of form elements that comprise the form.
358
 * @param array $context
359
 *   An associative array containing the following keys:
360
 *   - field: The $field array.
361
 *   - instance: The $instance array.
362
 *   - has_data: The value of $has_data.
363
 *
364
 * @see hook_field_settings_form()
365
 */
366
function hook_date_field_settings_form_alter(&$form, $context) {
367
  $field = $context['field'];
368
  $instance = $context['instance'];
369
  $has_data = $context['has_data'];
370

  
371
  $form['repeat'] = array(
372
    '#type' => 'select',
373
    '#title' => t('Repeating date'),
374
    '#default_value' => $field['settings']['repeat'],
375
    '#options' => array(0 => t('No'), 1 => t('Yes')),
376
    '#attributes' => array('class' => array('container-inline')),
377
    '#description' => t("Repeating dates use an 'Unlimited' number of values. Instead of the 'Add more' button, they include a form to select when and how often the date should repeat."),
378
    '#disabled' => $has_data,
379
  );
380
}
381

  
382
/**
383
 * Alter a date field instance settings form.
384
 *
385
 * @param array $form
386
 *   Nested array of form elements that comprise the form.
387
 * @param array $context
388
 *   An associative array containing the following keys:
389
 *   - field: The $field array.
390
 *   - instance: The $instance array.
391
 *
392
 * @see hook_field_instance_settings_form()
393
 */
394
function hook_date_field_instance_settings_form_alter(&$form, $context) {
395
  $field = $context['field'];
396
  $instance = $context['instance'];
397
  $form['new_setting'] = array(
398
    '#type' => 'textfield',
399
    '#default_value' => '',
400
    '#title' => t('My new setting'),
401
  );
402
}
403

  
404
/**
405
 * Alter a date field widget settings form.
406
 *
407
 * @param array $form
408
 *   Nested array of form elements that comprise the form.
409
 * @param array $context
410
 *   An associative array containing the following keys:
411
 *   - field: The $field array.
412
 *   - instance: The $instance array.
413
 *
414
 * @see hook_field_widget_settings_form()
415
 */
416
function hook_date_field_widget_settings_form_alter(&$form, $context) {
417
  $field = $context['field'];
418
  $instance = $context['instance'];
419
  $form['new_setting'] = array(
420
    '#type' => 'textfield',
421
    '#default_value' => '',
422
    '#title' => t('My new setting'),
423
  );
424
}
425

  
426
/**
427
 * Alter a date field formatter settings form.
428
 *
429
 * @param array $form
430
 *   Nested array of form elements that comprise the form.
431
 * @param array $form_state
432
 *   A keyed array containing the current state of the form.
433
 * @param array $context
434
 *   An associative array containing the following keys:
435
 *   - field: The $field array.
436
 *   - instance: The $instance array.
437
 *   - view_mode: The formatter view mode.
438
 *
439
 * @see hook_field_formatter_settings_form()
440
 */
441
function hook_date_field_formatter_settings_form_alter(&$form, &$form_state, $context) {
442
  $field = $context['field'];
443
  $instance = $context['instance'];
444
  $view_mode = $context['view_mode'];
445
  $settings = $context['settings'];
446
  $formatter = $context['formatter'];
447
  if ($formatter == 'date_default') {
448
    $form['show_repeat_rule'] = array(
449
      '#title' => t('Repeat rule:'),
450
      '#type' => 'select',
451
      '#options' => array(
452
        'show' => t('Show repeat rule'),
453
        'hide' => t('Hide repeat rule')),
454
      '#default_value' => $settings['show_repeat_rule'],
455
      '#access' => $field['settings']['repeat'],
456
      '#weight' => 5,
457
    );
458
  }
459
}
460

  
461
/**
462
 * Alter a date field formatter settings summary.
463
 *
464
 * @param array $summary
465
 *   An array of strings to be concatenated into a short summary of the
466
 *   formatter settings.
467
 * @param array $context
468
 *   An associative array containing the following keys:
469
 *   - field: The $field array.
470
 *   - instance: The $instance array.
471
 *   - view_mode: The formatter view mode.
472
 *
473
 * @see hook_field_formatter_settings_summary()
474
 */
475
function hook_date_field_formatter_settings_summary_alter(&$summary, $context) {
476
  $field = $context['field'];
477
  $instance = $context['instance'];
478
  $view_mode = $context['view_mode'];
479
  $formatter = $context['formatter'];
480
  $settings = $context['settings'];
481
  if (isset($settings['show_repeat_rule']) && !empty($field['settings']['repeat'])) {
482
    if ($settings['show_repeat_rule'] == 'show') {
483
      $summary[] = t('Show repeat rule');
484
    }
485
    else {
486
      $summary[] = t('Hide repeat rule');
487
    }
488
  }
489
}
date/date.devel_generate.inc
1
<?php
2

  
3
/**
4
 * @file
5
 * Date Devel Generate code.
6
 */
7

  
8
use Drupal\Core\Datetime\DrupalDateTime;
9

  
10
/**
11
 * Implements hook_devel_generate().
12
 *
13
 * Included only when needed.
14
 */
15
function date_devel_generate($entity, $field, $instance, $bundle) {
16

  
17
  $entity_field = array();
18
  if (isset($instance['widget']['settings']['year_range'])) {
19
    $split = explode(':', $instance['widget']['settings']['year_range']);
20
    $back = str_replace('-', '', $split[0]);
21
    $forward = str_replace('+', '', $split[1]);
22
  }
23
  else {
24
    $back = 2;
25
    $forward = 2;
26
  }
27
  // Pick a random year within the time range,
28
  // and a random second within that year.
29
  $year = date_format(new DrupalDateTime(), 'Y') - $back + mt_rand(0, ($forward + $back));
30
  $start = new DrupalDateTime($year . '-01-01 00:00:00', date_get_timezone_db($field['settings']['tz_handling']));
31
  $leap = date_format($start, 'L');
32
  $max_days = $leap ? 366 : 365;
33
  $seconds = mt_rand(0, ($max_days * 86400));
34
  date_modify($start, "+$seconds seconds");
35
  $increment = $instance['widget']['settings']['increment'];
36
  date_increment_round($start, $increment);
37

  
38
  // Modify End date by 1 hour to 3 days, shorter for repeating dates
39
  // longer for others.
40
  $start2 = clone($start);
41
  $max = !empty($field['settings']['repeat']) ? 720 : 4320;
42
  $max = 240;
43
  date_modify($start2, '+' . mt_rand(60, $max) . ' minutes');
44
  date_increment_round($start2, $increment);
45

  
46
  if ($field['settings']['tz_handling'] == 'date') {
47
    // Choose a random timezone.
48
    // Not all keys exist, so we have to check.
49
    $timezones = array_keys(system_time_zones(TRUE));
50
    $key = mt_rand(0, count($timezones) - 1);
51
    if (!array_key_exists($key, $timezones)) {
52
      $timezone = drupal_get_user_timezone();
53
    }
54
    else {
55
      $timezone = $timezones[$key];
56
    }
57
  }
58
  else {
59
    $timezone = date_get_timezone($field['settings']['tz_handling']);
60
  }
61

  
62
  $format = DATE_FORMAT_ISO;
63
  $entity_field['value'] = date_format($start, $format);
64
  if ($field['settings']['todate']) {
65
    $entity_field['value2'] = date_format($start2, $format);
66
  }
67
  date_timezone_set($start, timezone_open($timezone));
68
  $entity_field['timezone'] = $timezone;
69
  $entity_field['offset'] = date_offset_get($start);
70
  date_timezone_set($start2, timezone_open($timezone));
71
  $entity_field['offset2'] = date_offset_get($start2);
72
  return $entity_field;
73

  
74
}
date/date.field.inc
1
<?php
2

  
3
/**
4
 * @file
5
 * Field hooks to implement a date field.
6
 */
7

  
8
use Drupal\Core\Datetime\DrupalDateTime;
9

  
10
/**
11
 * Implements hook_field_is_empty().
12
 */
13
function date_field_is_empty($item, $field) {
14
  // Sometimes a $item is a date object.
15
  // Coming from repeating dates. Why??
16
  if (!is_array($item)) {
17
    return FALSE;
18
  }
19
  if (empty($item['value'])) {
20
    return TRUE;
21
  }
22
  elseif ($field['settings']['todate'] == 'required' && empty($item['value2'])) {
23
    return TRUE;
24
  }
25
  return FALSE;
26
}
27

  
28
/**
29
 * Implements hook_field_info().
30
 */
31
function date_field_info() {
32
  return array(
33
    'date' => array(
34
      'label' => 'Date Range',
35
      'description' => t('Store a start and optional end date in the database as ISO dates.'),
36
      'settings' => array(
37
        'todate' => '',
38
        'granularity' => drupal_map_assoc(array('year', 'month', 'day', 'hour', 'minute')),
39
        'tz_handling' => 'site',
40
        'timezone_db' => 'UTC',
41
      ),
42
      'instance_settings' => array(
43
        'default_value' => 'now',
44
        'default_value_code' => '',
45
        'default_value2' => 'same',
46
        'default_value_code2' => '',
47
      ),
48
      'default_widget' => 'date_select',
49
      'default_formatter' => 'date_default',
50
      'default_token_formatter' => 'date_plain',
51
      'field item class' => '\Drupal\date\Type\DateItem',
52
    ),
53
  );
54
}
55

  
56
/**
57
 * Implements hook_field_load().
58
 */
59
function date_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
60
  $timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
61
  $db_format = date_type_format($field['type']);
62
  $keys = date_available_values($field);
63
  foreach ($entities as $id => $entity) {
64
    foreach ($items[$id] as $delta => &$item) {
65
      // If the file does not exist, mark the entire item as empty.
66
      if (is_array($item)) {
67
        $item['data'] = isset($item['data']) ? unserialize($item['data']) : array();
68
        $item['timezone_db'] = $timezone_db;
69
        $item['date_type'] = $field['type'];
70
        if (!empty($field['settings']['cache_enabled']) && ($delta < $field['settings']['cache_count'] || $field['settings']['cache_count'] == 0)) {
71
          foreach ($keys as $key) {
72
            if (!empty($item[$key])) {
73
              $item['db'][$key] = $date;
74
            }
75
          }
76
        }
77
      }
78
    }
79
  }
80
}
81

  
82
/**
83
 * Implements hook_field_validate().
84
 */
85
function date_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
86
  $field_name = $field['field_name'];
87
  $flexible = 0;
88

  
89
  // @TODO Figure out what we need here now.
90
  return;
91

  
92
  // Don't try to validate if there were any errors before this point
93
  // since the element won't have been munged back into a date.
94
  if (!form_get_errors()) {
95
    foreach ($items as $delta => $item) {
96
      if (is_array($item) && isset($item['value'])) {
97
        $keys = date_available_values($field, $instance);
98
        $date1 = new DrupalDateTime($item['value'], $item['timezone'], date_type_format($field['type']));
99
        if (count($keys) == 1 || (empty($item['value2']) && $item['value2'] !== 0)) {
100
          $date2 = clone($date1);
101
        }
102
        else {
103
          $date2 = new DrupalDateTime($item['value2'], $item['timezone'], date_type_format($field['type']));
104
        }
105
/*
106
        $valid1 = $date1->validGranularity($field['settings']['granularity'], $flexible);
107
        $valid2 = $date2->validGranularity($field['settings']['granularity'], $flexible);
108

  
109
        foreach ($keys as $key) {
110
          if ($ == 'value' && $field['settings']['todate'] && !$valid1 && $valid2) {
111
            $errors[$field['field_name']][$langcode][$delta][] = array(
112
              'error' => 'value',
113
              'message' => t("A 'Start date' date is required for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => $instance['label'])),
114
            );
115
          }
116
          if ($key == 'value2' && $field['settings']['todate'] == 'required' && ($instance['required'] && $valid1 && !$valid2)) {
117
            $errors[$field['field_name']][$langcode][$delta][] = array(
118
              'error' => 'value2',
119
              'message' => t("An 'End date' is required for field %field #%delta.", array('%delta' => $field['cardinality'] ? intval($delta + 1) : '', '%field' => $instance['label'])),
120
            );
121
          }
122
        }
123
*/
124
      }
125
    }
126
  }
127
}
128

  
129
/**
130
 * Implements hook_field_insert().
131
 */
132
function date_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
133
  $field_name = $field['field_name'];
134

  
135
  if (empty($items)) {
136
    return;
137
  }
138
  // Add some information needed to interpret token values.
139
  $values = $items;
140
  foreach ($values as $delta => $item) {
141
    $timezone = isset($item['timezone']) ? $item['timezone'] : '';
142
    if (is_array($item)) {
143
      $items[$delta]['timezone'] = date_get_timezone($field['settings']['tz_handling'], $timezone);
144
      $items[$delta]['timezone_db'] = date_get_timezone_db($field['settings']['tz_handling']);
145
      $items[$delta]['date_type'] = $field['type'];
146
      $data = array();
147
      foreach (date_data_keys() as $key) {
148
        if (isset($item[$key])) {
149
          $data[$delta][$key] = $item[$key];
150
          unset($items[$delta][$key]);
151
        }
152
      }
153
      $items[$delta]['data'] = serialize($data);
154
    }
155
  }
156
  $entity->{$field['field_name']}[$langcode] = $items;
157
}
158

  
159
/**
160
 * Implements hook_field_insert().
161
 */
162
function date_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
163
  $context = array(
164
    'entity_type' => $entity_type,
165
    'entity' => $entity,
166
    'field' => $field,
167
    'instance' => $instance,
168
    'langcode' => $langcode,
169
  );
170
  drupal_alter('date_field_insert', $items, $context);
171
}
172

  
173
/**
174
 * Implements hook_field_update().
175
 */
176
function date_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
177
  $context = array(
178
    'entity_type' => $entity_type,
179
    'entity' => $entity,
180
    'field' => $field,
181
    'instance' => $instance,
182
    'langcode' => $langcode,
183
  );
184
  drupal_alter('date_field_update', $items, $context);
185
}
186

  
187
/**
188
 * Implements hook_field_instance_settings_form().
189
 *
190
 * Wrapper functions for date administration, included only when processing
191
 * field settings.
192
 */
193
function date_field_instance_settings_form($field, $instance) {
194
  module_load_include('inc', 'date', 'date_admin');
195
  return _date_field_instance_settings_form($field, $instance);
196
}
197

  
198
/**
199
 * Implements hook_field_settings_form().
200
 */
201
function date_field_settings_form($field, $instance, $has_data) {
202
  module_load_include('inc', 'date', 'date_admin');
203
  return _date_field_settings_form($field, $instance, $has_data);
204
}
205

  
date/date.info
1
name = Date
2
description = Makes date/time fields available.
3
dependencies[] = date_api
4
package = Date/Time
5
core = 8.x
6

  
7
; Information added by drupal.org packaging script on 2013-09-30
8
version = "8.x-1.x-dev"
9
core = "8.x"
10
project = "date"
11
datestamp = "1380568702"
12

  
date/date.install
1
<?php
2

  
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the Date module.
6
 */
7

  
8
/**
9
 * Implements hook_field_schema().
10
 */
11
function date_field_schema($field) {
12
  switch ($field['settings']['todate']) {
13
    case '':
14
      $db_columns = array(
15
        'value' => array(
16
          'description' => 'The date value',
17
          'type' => 'varchar',
18
          'length' => 20,
19
          'not null' => FALSE,
20
        ),
21
        'data' => array(
22
          'description' => 'A serialized array with more date info.',
23
          'type' => 'text',
24
          'not null' => FALSE,
25
        ),
26
      );
27
      $indexes = array(
28
        'value' => 'value',
29
      );
30
      break;
31
    default:
32
      $db_columns = array(
33
        'value' => array(
34
          'description' => 'The start date value',
35
          'type' => 'varchar',
36
          'length' => 20,
37
          'not null' => FALSE,
38
        ),
39
        'value2' => array(
40
          'description' => 'The end date value',
41
          'type' => 'varchar',
42
          'length' => 20,
43
          'not null' => FALSE,
44
        ),
45
        'data' => array(
46
          'description' => 'A serialized array with more date info.',
47
          'type' => 'text',
48
          'not null' => FALSE,
49
        ),
50
      );
51
      $indexes = array(
52
        'value' => 'value',
53
        'value2' => 'value2',
54
      );
55
      break;
56
  }
57

  
58
  // If a second date is needed for 'End date', make a copy of the first one.
59
  // Timezone and offset columns are used only if date-specific dates are used.
60
  if (isset($field['settings']['tz_handling']) && $field['settings']['tz_handling'] == 'date') {
61
    $db_columns['offset'] = array(
62
      'type' => 'int',
63
      'not null' => FALSE,
64
    );
65
    if (!empty($field['settings']['todate'])) {
66
      $db_columns['offset2'] = array('type' => 'int', 'not null' => FALSE);
67
    }
68
  }
69
  return array('columns' => $db_columns, 'indexes' => $indexes);
70
}
71

  
72
/**
73
 * Implements hook_update_last_removed().
74
 */
75
function date_update_last_removed() {
76
  return 7004;
77
}
78

  
79
// @TODO Write upgrade path for text widgets to combine them with Popup widgets as new 'Datetime' widgets.
80
// @TOTO Write upgrade path for select widgets convert them to new 'Datelist' widgets.
81
// @TODO Write upgrade path for 'input_format' widget settings to create 'date_date_format' and 'date_time_format', date_date_element, date_time_element.
82
// @TODO Write upgrade path to remove 'input_format_custom'.
83
// @TODO Write upgrade path to remove datetime and datestamp storage methods and make all into iso.
84
// @TODO Removing custom formats that won't work in datepicker for consistency.
85
// @TODO Write upgrade path adding indexes, if not already set.
86
// @TODO Write upgrade path to add timezone, rrule, and all_day into new data column and delete rrule and timezone columns.
date/date.js
1
(function ($) {
2

  
3

  
4
Drupal.behaviors.dateSelect = {};
5

  
6
Drupal.behaviors.dateSelect.attach = function (context, settings) {
7
  var $widget = $('.form-type-date-select').parents('fieldset').once('date');
8
  var i;
9
  for (i = 0; i < $widget.length; i++) {
10
    new Drupal.date.EndDateHandler($widget[i]);
11
  }
12
};
13

  
14
Drupal.date = Drupal.date || {};
15

  
16
/**
17
 * Constructor for the EndDateHandler object.
18
 *
19
 * The EndDateHandler is responsible for synchronizing a date select widget's
20
 * end date with its start date. This behavior lasts until the user
21
 * interacts with the end date widget.
22
 *
23
 * @param widget
24
 *   The fieldset DOM element containing the from and to dates.
25
 */
26
Drupal.date.EndDateHandler = function (widget) {
27
  this.$widget = $(widget);
28
  this.$start = this.$widget.find('.form-type-date-select[class$=value]');
29
  this.$end = this.$widget.find('.form-type-date-select[class$=value2]');
30
  if (this.$end.length == 0) {
31
    return;
32
  }
33
  this.initializeSelects();
34
  // Only act on date fields where the end date is completely blank or already
35
  // the same as the start date. Otherwise, we do not want to override whatever
36
  // the default value was.
37
  if (this.endDateIsBlank() || this.endDateIsSame()) {
38
    this.bindClickHandlers();
39
    // Start out with identical start and end dates.
40
    this.syncEndDate();
41
  }
42
};
43

  
44
/**
45
 * Store all the select dropdowns in an array on the object, for later use.
46
 */
47
Drupal.date.EndDateHandler.prototype.initializeSelects = function () {
48
  var $starts = this.$start.find('select');
49
  var $end, $start, endId, i, id;
50
  this.selects = {};
51
  for (i = 0; i < $starts.length; i++) {
52
    $start = $($starts[i]);
53
    id = $start.attr('id');
54
    endId = id.replace('-value-', '-value2-');
55
    $end = $('#' + endId);
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff