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.
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?
Comment | File | Size | Author |
---|---|---|---|
#2 | date_popup_authored-author_intex_error-1980316.patch | 969 bytes | dafeder |
Comments
Comment #1
Mark TrappMarking 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 toFALSE
(something Date Popup Authored should be fine with).Comment #1.0
Mark TrappRemoved strong tags out of code tags
Comment #2
dafederHere is the thing - the only test this module gives for whether we're on an appropriate node form is
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.
Comment #3
Mark TrappAlready 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.
Comment #4
Mark Trapp