Comments

sgarsivaz created an issue. See original summary.

amir jamshidi’s picture

Version: 8.x-3.6 » 4.0.2
Issue tags: +ajax error

hi. I use Drupal 10.2.3 , calendar_systems Version: 4.0.2 and webform 6.2.2 but get this error in webform add element

TypeError: function_exists(): Argument #1 ($function) must be of type string, array given in function_exists() (line 178 of /modules/contrib/calendar_systems/src/Element/CalendarSystemsDateTime.php).

I change

if (function_exists($callback))

to

if (function_exists($callback[1]))

in /modules/contrib/calendar_systems/src/Element/CalendarSystemsDateTime.php line 178 and 210

arefen’s picture

Thanks, Amir
your solution works for me

naeim’s picture

Hi everyone,

I encountered the same error with Drupal 10.2.3, calendar_systems 4.0.2, and Webform 6.2.2:

TypeError: function_exists(): Argument #1 ($function) must be of type string, array given in function_exists() (line 178 of /modules/contrib/calendar_systems/src/Element/CalendarSystemsDateTime.php).

To fix this, I modified the code to check if the callback is a string before calling `function_exists()`. Here’s the relevant snippet I used:

if (is_string($callback) && function_exists($callback)) {
  $callback($element, $form_state, $date);
}

This prevents passing an array (or other non-string types) to function_exists(), which causes the TypeError.

I applied this check in both #date_date_callbacks and #date_time_callbacks loops. After this change, the error stopped occurring and the webform element addition works properly.

I believe this is a safer and cleaner fix than assuming the callback is an array or accessing $callback[1].

amir jamshidi’s picture

Issue summary: View changes
StatusFileSize
new1.07 KB

You are right Naeim. You suggested a better way. I will turn these changes into a patch file so that everyone can use it. I hope these changes will be applied to the module in future versions.

doxigo’s picture

Status: Active » Fixed

This is fixed, will tag a new release soon, thanks everyone

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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