I use the Working hours field type that has a couple of date_popup elements in it. I use field_access to remove access to the field for certain roles. Normally this should prevent the modification of the field, but in my situation, whenever I save the node with the field, and there is no field access, I got integrity constraint violation
, because the field was not processed and the value was not correctly set. There are a couple of places where the processing is short-circuited and this makes some sense, since there is javascript that would be attached, when it doesn't need to be attached:
function date_popup_element_process($element, &$form_state, $form) {
if (date_hidden_element($element)) {
return $element;
}
function date_popup_validate($element, &$form_state) {
if (date_hidden_element($element)) {
return;
}
But this changes what the value is in my situation where the date_popup is hidden, because of #access, but I still need it to be processed. As a result I get:
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'field_opening_hours_from'
I think the solution would be not to stop processing but maybe just to prevent the attaching of js/css, so to prevent the call to date_popup_add()
, but also there are the settings being added in date_popup_js_settings_id()
. Maybe the best approach would be to convert all js/css loading to #attached, which would automatically make sure they don't get added, unless element is rendered.
Comment | File | Size | Author |
---|
Comments
Comment #1
MiroslavBanov CreditAttribution: MiroslavBanov commentedFor now attaching the easy solution that just does not prevent processing when date_popup element is hidden.
Comment #2
Valentine94Bot
Comment #3
sergei_brill CreditAttribution: sergei_brill commentedI have same problem when '#access' is set to false on a date_popup field. The patch helped me. I agree MiroslavBanov's idea to use function date_hidden_element to prevent from adding js/css. But element must be still processed on server side since '#access' => FALSE doesn't mean the field will be excluded from the form at all. It means only that the field will be not displayed to user but value from the field still has to be processed.
Probably, other widgets has same problem because of using of this function.
Comment #4
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 3 year old patch to date_popup.module does not apply to the latest 7.x-2.x-dev and may be too old to easily reroll, but I went ahead and tagged the issue accordingly.