Error when adding an event when a hour is missing

Created on 8 June 2018, over 6 years ago
Updated 14 January 2024, 11 months ago

Hi,

The granularity of event type is "per hour".
This error occurs when a hour is not completed :

TypeError : DateTime::__construct() expects parameter 1 to be string, array given dans DateTime->__construct() (line 449 on /sites/all/modules/bat/modules/bat_event/bat_event.admin.inc).

To fix it, I changed the file "bat_event.admin.inc" like that :

function bat_event_edit_form_validate(&$form, &$form_state) {
  // Notify field widgets to validate their data.
  entity_form_field_validate('bat_event', $form, $form_state);

  $event_type = bat_event_type_load($form_state['values']['type']);
  $target_field_name = 'event_' . $event_type->target_entity_type . '_reference';
  if ($event_type->fixed_event_states) {
-    if ($form_state['values']['bat_start_date'] != '' && $form_state['values']['bat_end_date'] != '' &&                                                                                                         
-        $form_state['values'][$target_field_name][LANGUAGE_NONE][0]['target_id'] != '') {
+  if ($form_state['values']['bat_start_date'] != '' && is_string($form_state['values']['bat_start_date'])
+        && $form_state['values']['bat_end_date'] != '' && is_string($form_state['values']['bat_end_date'])
+        && $form_state['values'][$target_field_name][LANGUAGE_NONE][0]['target_id'] != '') {
      global $databases;

      $prefix = (isset($databases['default']['default']['prefix'])) ? $databases['default']['default']['prefix'] : '';

      $event_store = new DrupalDBStore($event_type->type, DrupalDBStore::BAT_EVENT, $prefix);

      $start_date = new DateTime($form_state['values']['bat_start_date']);
      $end_date = new DateTime($form_state['values']['bat_end_date']);
      $end_date->sub(new DateInterval('PT1M'));

It's not need to validate the form in 'bat_event" module because the validation of the date has already failed.

Regards,
Detroz

🐛 Bug report
Status

Closed: outdated

Version

1.33

Component

Code

Created by

🇧🇪Belgium detroz

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024