1.0 Problem/Motivation
When there are more than ~475 Groups in a CiviCRM system, it is not possible to save the "Edit Group(s) element" dialog when building a webform. Disabling groups does not help, but temporarily setting their is_hidden flag (using SQL) seems to provide a workaround.
2.0 Detailed steps to reproduce (embed screenshots)
- Install a clean copy of Drupal 9 with CiviCRM and webform_civicrm. This has been tested on Drupal 9.3.15, CiviCRM 5.50.1, and webform_civicrm 6.2.0.
- Install this extension to create many Groups (intended for development sites only): https://github.com/AsylumSeekersCentre/au.org.asylumseekerscentre.create...
- Use API Explorer v3 to call Group.createmany with number_to_create set to 500
- Create a new webform
- Enable CiviCRM processing on the webform
- Set the "Number of Contacts" to 1 in the CiviCRM section
- Set "Enable Tags and Groups Fields" to "Yes"
- Set "Group(s)" to "User Select" and press Save Settings
- Switch to the Build tab of the webform
- Edit the "Group(s)" element
- Change the radio button from "Live Options" to "Static Options"
- Use the checkbox in the headings to deselect all of the options
- Select a small number of Groups (I used the first three in the list, including the Administrators group)
- Scroll to the bottom and press Save
- Note that after the wheel finishes spinning, the Edit dialog does not disappear as it usually would
- Close the Edit dialog and open it again
- Note that the Static Options selection has not been saved, and it's still set to Live Options
3.0 Proposed resolution
Ideally, it would cope with any number of Groups available on the system, if a sane number are added to the webform.
Alternatively, a workaround might be to treat Disabled groups the same way it treats Hidden groups (that is, exclude them from the list of static options). This would allow admins to keep the set of enabled groups below the threshold at which it starts to fail, without having to delete all of the old groups.
4.0 Other notes
No messages appear in the Drupal log after the failure occurs.
This issue might affect other long lists of "CiviCRM Options", but we've only encountered it with Groups.
With around 460 groups, the failure occurs when trying to add all of them to the webform as static options, but it works when only adding three. Somewhere around 475 groups, saving always fails.
The SQL field which stores the webform configuration is a longblob, so it's very unlikely to be exceeding the maximum storage size for the field.
My attempts to trace the failure using xdebug have shown that it lands in the onException method of this class:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21Ev...
The stack trace at that point looks like this:
[0] Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException @ /var/www/clean_d9/web/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php:83
[1] call_user_func:{/var/www/clean_d9/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:142} @ /var/www/clean_d9/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:142
[2] Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch @ /var/www/clean_d9/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:142
[3] Symfony\Component\HttpKernel\HttpKernel->handleThrowable @ /var/www/clean_d9/vendor/symfony/http-kernel/HttpKernel.php:219
[4] Symfony\Component\HttpKernel\HttpKernel->handle @ /var/www/clean_d9/vendor/symfony/http-kernel/HttpKernel.php:91
[5] Drupal\Core\StackMiddleware\Session->handle @ /var/www/clean_d9/web/core/lib/Drupal/Core/StackMiddleware/Session.php:58
[6] Drupal\Core\StackMiddleware\KernelPreHandle->handle @ /var/www/clean_d9/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:48
[7] Drupal\page_cache\StackMiddleware\PageCache->pass @ /var/www/clean_d9/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:106
[8] Drupal\page_cache\StackMiddleware\PageCache->handle @ /var/www/clean_d9/web/core/modules/page_cache/src/StackMiddleware/PageCache.php:85
[9] Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle @ /var/www/clean_d9/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:48
[11] Stack\StackedHttpKernel->handle @ /var/www/clean_d9/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23
[12] Drupal\Core\DrupalKernel->handle @ /var/www/clean_d9/web/core/lib/Drupal/Core/DrupalKernel.php:708
[13] {main} @ /var/www/clean_d9/web/index.php:19
I haven't figured out where to go from there to diagnose the problem.
Also (and perhaps this should be a separate issue), changing the "Type" from "CiviCRM Options" to "Select" or "Select other" causes a different failure (when there are too many groups, as above). When pressing the minus button to remove a group from a Select list (still in the "Edit Group(s) element" dialog), it presents this error message:
An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (3.91 GB) that this server supports.
Originally the error message said the maximum size was 2 MB, so I increased it to an unrealistic value to confirm that it's not solved by changing the post_max_size and upload_max_filesize PHP limits.