When using Date Popup calendar and choosing time skip option, an "Undefined index" warning occurs on a scheduled node save. This occurs only when date_popup module is used together and there's no problem for the functionality.

Notice: Undefined index: time in scheduler_date_popup_pre_validate_alter() (line 917 of /drupal_root/sites/all/modules/contrib/scheduler/scheduler.module).

The steps to reproduce:

1. Set up Drupal 7.43.
2. Install and enable Scheduler and Date (date_popup) modules.
3. Use "Date Popup calendar" and "Allow users to enter only a date and provide a default time" option. The page path is `/admin/config/content/scheduler` .
4. Enable Scheduling function on a content type. For example, Article. The page path is `/admin/structure/types/manage/article`.
5. Create a node with "Publish on" date.
6. Check the log. You can see the above warning.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hgoto created an issue. See original summary.

hgoto’s picture

Status: Active » Needs review
FileSize
945 bytes

Here is a patch to solve this warning. The index is not always available and `empty()` should be used here. The module for Drupal 8 doesn't implement the same function (integration with Date Popup). So I created a patch only for Drupal 7. I hope someone would review this. Thank you.

hgoto’s picture

Additional information: this phenomenon can be seen in the current latest version 7.x-1.4.

jonathan1055’s picture

Hello hgoto,
Thanks for the detailed explanation. However, it is strange that you have this error, because I do not get it. There must be something different between our drupal site setups. If I had seen this error before I would have corrected it! I have a few questions:

  1. What php version are you using? I'm on 5.5.27
  2. What type of date-picker are you using? see /admin/config/date/date_popup
  3. When selecting a date, do you also have a time entry field which you leave blank?
  4. What are the relative weights of your Scheduler and Date modules? Look in db table called system.

In my scheduler_date_popup_pre_validate_alter() I always get a 'time' value in the input array:

-- scheduler_date_popup_pre_validate_alter --
original $input: Array
(
    [date] => 26/04/2016
    [time] => 
)

$default_time: 1461604500
$input after setting default: Array
(
    [date] => 26/04/2016
    [time] => 18:15
)

If you want to try it, the above debug was created using:

/**
 * Implements hook_date_popup_pre_validate_alter().
 */
function scheduler_date_popup_pre_validate_alter($element, $form_state, &$input) {
  dd('-- scheduler_date_popup_pre_validate_alter --');
  dd($input, 'original $input');
  // Provide a default time if this is enabled and the time field is empty.
  if (variable_get('scheduler_allow_date_only', FALSE) && $element['#array_parents'][0] == 'scheduler_settings' && $input['date'] != '' && $input['time'] == '') {
    // Get the default time as a timestamp number.
    $default_time = strtotime(variable_get('scheduler_default_time', SCHEDULER_DEFAULT_TIME));
    dd($default_time, '$default_time');
    // Set the time in the required format just as if the user had typed it.
    $input['time'] = format_date($default_time, 'custom', variable_get('scheduler_time_only_format', SCHEDULER_TIME_ONLY_FORMAT));
    dd($input, '$input after setting default');
  }
  dd('-- scheduler_date_popup_pre_validate_alter -- END');
}
hgoto’s picture

Hi jonathan1055, thank you for your reaction. I see. I'll answer the questions as much as possible.

1. What php version are you using? I'm on 5.5.27

My php version is 5.6.20.

2. What type of date-picker are you using? see /admin/config/date/date_popup

I didn't change it. I use "Use default jQuery timepicker" which is the default one.

3. When selecting a date, do you also have a time entry field which you leave blank?

I don't have that. The time entry field is not displayed and only the date entry field is shown.

Probably it's because I changed the "Date format" of Scheduler field setting. (I'm sorry, I forgot to this point in the steps...)

Please visit the Scheduler settings page `/admin/config/content/scheduler` and change "Date format" field value to "Y-m-d" (delete the time part). And again, please create or edit a node. I think it's necessary to do this to reproduce the phenomenon.

4. What are the relative weights of your Scheduler and Date modules? Look in db table called system.

The module weights are as following:

- Scheduler: 0.
- Date: 0.
- Date Popup: 0.

I didn't change the values.

...

I used the same `dd()` debug as you did. I checked the phenomenon again. Then, the 'time' key is there when I use the date format "Y-m-d H:i:s" and it's not there when I use the format "Y-m-d".

If there is any points I should share, please tell me. Thank you for your time.

hgoto’s picture

Assigned: hgoto » Unassigned
jonathan1055’s picture

Title: "Undefined index" warning occurs on a scheduled node save » Undefined index: time in scheduler_date_popup_pre_validate_alter()
Assigned: Unassigned » jonathan1055

Yes, that's it. If the time part is removed then the $input array does not have 'time' key. Interestingly, the devel module backtrace has some fault in it, which means the warning was not being shown for me. When I removed the krumo backtrace display and reverted to 'standard drupal' the warning then showed up.

I will make this change. There is no corresponding fault in 8.x because currently we do not use the scheduler format for the date pop-up, and this conversion has not been decided yet.

hgoto’s picture

I got it. Thank you for checking and kind description!

  • jonathan1055 committed 1eedeb4 on 7.x-1.x authored by hgoto
    Issue #2712779 by hgoto, jonathan1055: Undefined index: time in...
jonathan1055’s picture

Status: Needs review » Fixed

I also took the opportunity to use !empty() on the date array key, as that is safer than testing for != ''

Thank you, hgoto.

jonathan1055’s picture

Assigned: jonathan1055 » Unassigned
hgoto’s picture

I see. jonathan1055, thank you for your speedy action.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.