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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MiroslavBanov’s picture

For now attaching the easy solution that just does not prevent processing when date_popup element is hidden.

Valentine94’s picture

Status: Active » Needs review

Bot

sergei_brill’s picture

I 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.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll, +Needs rework

The 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.

Checking patch date_popup/date_popup.module...
Hunk #1 succeeded at 297 (offset 24 lines).
error: while searching for:
function date_popup_validate($element, &$form_state) {

  if (date_hidden_element($element)) {
    return;
  }

  if (is_string($element['#value'])) {

error: patch failed: date_popup/date_popup.module:461
error: date_popup/date_popup.module: patch does not apply