Can not add element to webform

Created on 11 November 2023, over 1 year ago

Problem/Motivation

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

Steps to reproduce

drupal = 9.5.11

webform

calendar_systems = 8.x-3.6

when you want to add element by "Add element" button. we encountered this error.

๐Ÿ› Bug report
Status

Active

Version

3.6

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ทIran sgarsivaz

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

Comments & Activities

  • Issue created by @sgarsivaz
  • ๐Ÿ‡ฎ๐Ÿ‡ทIran amir jamshidi

    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).

  • ๐Ÿ‡ฎ๐Ÿ‡ทIran arefen

    Thanks, Amir
    your solution works for me

  • ๐Ÿ‡ณ๐Ÿ‡ดNorway naeim

    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].

Production build 0.71.5 2024