Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am seeing this message when creating an election:
Warning: strtotime() expects parameter 1 to be string, array given in ElectionDefaultController->save() (line 26 of .../modules/election/includes/election-default.controller.inc).
Comment | File | Size | Author |
---|---|---|---|
#10 | election-strtotime_array-2636366-10.patch | 4.76 KB | Liam Morland |
#8 | election-strtotime_array-2636366-8.patch | 4.8 KB | pjcdawkins |
#7 | election-strtotime_array-2636366-7.patch | 652 bytes | Liam Morland |
#5 | election-strtotime_array-2636366-5.patch | 668 bytes | Liam Morland |
| |||
#3 | election-2636366-3.patch | 2.21 KB | pjcdawkins |
Comments
Comment #2
pjcdawkins CreditAttribution: pjcdawkins commentedOK, this is probably because of an unexpected output from the date widget... I'll have a look. Also this handling should be in the form submit function, it's too magic to be in the controller.
Comment #3
pjcdawkins CreditAttribution: pjcdawkins commentedThis moves the logic out of the controller, but I don't know the cause of your issue yet.
Do you have the
date_popup
module enabled? Have you modified the election form via ...form_alter at all?Comment #4
Liam MorlandThe patch does not fix it. We are using the date_popup module, so the $value is an array of date and time. Setting the schedule still works.
Comment #5
Liam MorlandThis patch converts array to string before strtotime() is called. Array to string conversion code is borrowed from election_form_validate().
Comment #6
pjcdawkins CreditAttribution: pjcdawkins commentedIt looks like the logic is backwards in the ternary conditional: there should perhaps be an empty() around $value['time']
Comment #7
Liam MorlandThanks. Corrected version attached.
This raises a question about election_form_validate() which contains the same backwards logic several times.
Comment #8
pjcdawkins CreditAttribution: pjcdawkins commentedOK, here's something which also fixes election_form_validate(), via a separate function
Comment #9
Liam MorlandThis should probably be in a child issue. One comment: election_normalize_datetime() can return 0 if the date/time is empty. But 0 is a valid timestamp. Perhaps it should return NULL in this condition.
Comment #10
Liam MorlandHere is a version of your patch in #8 with minor adjustments to election_normalize_datetime().
Comment #13
Liam MorlandComment #14
pjcdawkins CreditAttribution: pjcdawkins as a volunteer commentedI wonder if we should just return FALSE early, if
empty($datetime)
?Comment #15
Liam MorlandDo you mean adding something like this to the top of election_normalize_datetime():
That is probably OK in practice, though technically zero is a valid datestamp and it would cause it to return false for that.
Comment #16
Liam MorlandOr the empty string check could be done first. The would cause many empty() value to return FALSE right away.
Comment #17
Liam MorlandInteger dates are probably more common, so the current order is probably best.
Comment #18
pjcdawkins CreditAttribution: pjcdawkins as a volunteer commentedI'd find it unlikely that anyone is scheduling an election for 1970-01-01 00:00:00. But you're right that 0 should return 0. So I'd say this is good as-is.
A unit test would be nice.
Comment #20
Liam MorlandComplete with unit test.