This error pops up when you have a date popup in an exposed Views form and want Views to remember the value.
What happens:
- The form is submitted with a correct date popup value (thus as an array with date/time entries).
- The form is validated and date popup "massages" (as put in the function comments) the value into a string (in function date_popup_validate) and puts that back into the form_state['values'].
- Views stores the values in $_SESSION so it can repopulate an exposed form later on.
Later on:
- Views populates $form_state['input'] using $_SESSION, thus putting a string in the value for the date popup element
- The function date_popup_element_value_callback gets called with a string as $input, is assigned to $return after which $return['date'], that is $return[0], that is the first character of the string is set to a strange value.
Solution: I think the easiest way to solve this is to accept strings in date_popup_element_value_callback() as $input and convert them to a date/time array first before processing.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 1342874-1.patch | 2.84 KB | fietserwin |
Comments
Comment #1
fietserwinAttached a patch that solves this problem. Some notes about the patch:
- You can't give a 2nd parameter a default value and then pass in a 3rd parameter (by reference and without default).
- $return will be assigned a value at the end of the function. Any earlier assignment will be overwritten and is thus useless.
- The lines to get a date object form a string are copied from function date_popup_input_date().
- After the problem was solved in function date_popup_element_value_callback(), a validation problem occurred at function date_popup_validate(), so I added code to accept a string there as well.
Comment #2
tim.plunkettThis is just a mistake in the parameters, it should be
date_popup_element_value_callback($element, $input = FALSE, $form_state = array())What was wrong with this line?
This is a confusing ternary. It should just be a 3 line `if` statement for clarity.
Changes like this make the patch harder to review.
Comment #3
gynekolog commentedthx