Using this module when the Conditonal Fields module is enabled throws the following error on the Conditional Field admin page.

/admin/structure/dependencies

As fix I just wrote a check on $form['author'] around the code:

if(isset($form['author'])) {
      if (!($form['author']['#access'] && variable_get('date_popup_authored_enabled_' . $form['type']['#value'], 1))) {
        return;
      }
    

      $form['author']['date']['#type'] = 'date_popup';

      // If there is a date already available, rewrite it to conform to
      // Date Popup's expected format.
      if (!empty($form['author']['date']['#default_value'])) {
        $date = new DateObject($form['author']['date']['#default_value'], NULL, 'Y-m-d H:i:s O');
        $form['author']['date']['#default_value'] = $date->format('Y-m-d H:i:s');
      }

      // Set options specific to date_popup.
      $year_range = variable_get('date_popup_authored_year_range_' . $form['type']['#value'], 3);
      $form['author']['date']['#date_year_range'] = '-' . $year_range . ':+' . $year_range;
      $form['author']['date']['#date_format'] = variable_get('date_popup_authored_format_' . $form['type']['#value'], 'm/d/Y - H:i');

      // Unset options that are not relevant to date_popup
      unset($form['author']['date']['#maxlength']);
      unset($form['author']['date']['#description']);

      // We need to modify date popup's data during submit
      // @see http://drupal.org/node/847854
      $form['#submit'][] = 'date_popup_authored_node_form_submit';
    }
}

Can anyone confirm this problem or confirm that this is a decent enough fix?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mark Trapp’s picture

Status: Needs work » Closed (duplicate)

Marking this as a duplicate of #977632: Date Popup Authored throws error if Authoring Information fieldset is removed. Date Popup Authored relies on core data structures: if a module goes ahead and removes one of them, it'll lead to unexpected results.

That Conditional Fields is unsetting $form['author'] entirely looks to be a bug more than anything: the appropriate way to disable access to an element is to set the #access property to FALSE (something Date Popup Authored should be fine with).

Mark Trapp’s picture

Issue summary: View changes

Removed strong tags out of code tags

dafeder’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active
FileSize
969 bytes

Here is the thing - the only test this module gives for whether we're on an appropriate node form is

if (strstr($form_id, '_node_form') !== FALSE) {

This is bound to produce false positives. For instance, I have the subscriptions module installed, which includes a form with the ID subscriptions_ui_node_form. A better approach seems to me to use hook_form_node_form_alter() to make sure we catch node forms but not other forms that would be caught up in that str matching function.

I also think it's reasonable to check to make sure the form has an author field before proceeding. Here's a patch that accomplishes both.

Mark Trapp’s picture

Assigned: dieterlwrs » Unassigned
Status: Active » Closed (duplicate)

Already fixed in commit baf31c. Looks like I forgot to update the duplicate references on this issue. Please use the latest dev version and see #1090164-3: Date Popup Authored does not play nice when $form['authored']['#access'] is modified too late for important caveats.