Problem/Motivation
For many display fields, autocompletion of existing contacts is broken. This includes Current Employer, Email, City, District/County, State/Province, Country, Postal Code, and Phone. If any of these are part of the selected display fields, the autocompletion throws an error.
The exact rules when an error is thrown seem to depend on whether the user is anonymous or not and whether only display fields as stated above are selected:
- anonymous user: always getting an error
- non-anonymous user & only selecting fields stated above: getting an error
- non-anonymous user & also selecting fields not stated above: not getting an error
Detailed steps to reproduce
Create a new webform, then:
Add existing contact
- Go to CiviCRM
- Check Enable CiviCRM Processing
- Number of Contacts:
1
- Under 1. Contact 1 → Contact Fields Make sure that Existing Contact is checked
- Click Save Settings
Display city for existing contact
- Go to Build
- Edit Existing Contact
- Set Form display → Form Widget to Autocomplete
- At Form display → Contact Display Field(s) select Display Name and City
- Click Save
Make form available
- Go to Settings
- Set URL path settings → Webform URL alias, e.g., to
/test
- Click Save
Fill form and notice error
- As anonymous user, navigate to the form (e.g., at
/test
)
- Start typing into field Existing Contact
- Notice HTTP 500 in browser console
In Drupal's error log, the following error of type php
can be found:
CRM_Core_Exception: Invalid field 'address.city' in Civi\Api4\Query\Api4SelectQuery->getField() (line 400 of /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4SelectQuery.php).
Backtrace:
#0 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(168): Civi\Api4\Query\Api4SelectQuery->getField()
#1 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(246): Civi\Api4\Query\Api4Query->getExpression()
#2 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(215): Civi\Api4\Query\Api4Query->composeClause()
#3 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(201): Civi\Api4\Query\Api4Query->treeWalkClauses()
#4 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4SelectQuery.php(230): Civi\Api4\Query\Api4Query->treeWalkClauses()
#5 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(80): Civi\Api4\Query\Api4SelectQuery->buildWhereClause()
#6 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(90): Civi\Api4\Query\Api4Query->getSql()
#7 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4SelectQuery.php(106): Civi\Api4\Query\Api4Query->getResults()
#8 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Generic/DAOGetAction.php(107): Civi\Api4\Query\Api4SelectQuery->run()
#9 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Generic/DAOGetAction.php(94): Civi\Api4\Generic\DAOGetAction->getObjects()
#10 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Provider/ActionObjectProvider.php(70): Civi\Api4\Generic\DAOGetAction->_run()
#11 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(156): Civi\Api4\Provider\ActionObjectProvider->invoke()
#12 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Generic/AbstractAction.php(256): Civi\API\Kernel->runRequest()
#13 /var/www/[HOST]/vendor/civicrm/civicrm-core/api/api.php(91): Civi\Api4\Generic\AbstractAction->execute()
#14 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/Utils.php(634): civicrm_api4()
#15 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/ContactComponent.php(154): Drupal\webform_civicrm\Utils->wf_civicrm_api4()
#16 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/WebformAjax.php(85): Drupal\webform_civicrm\ContactComponent->wf_crm_contact_search()
#17 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/Controller/AjaxController.php(53): Drupal\webform_civicrm\WebformAjax->contactAjax()
#18 [internal function]: Drupal\webform_civicrm\Controller\AjaxController->handle()
#19 /var/www/[HOST]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#20 /var/www/[HOST]/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /var/www/[HOST]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#22 /var/www/[HOST]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#23 /var/www/[HOST]/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#24 /var/www/[HOST]/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#25 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#26 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#27 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#28 /var/www/[HOST]/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#29 /var/www/[HOST]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#30 /var/www/[HOST]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch()
#31 /var/www/[HOST]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup()
#32 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#33 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#34 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#35 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#36 /var/www/[HOST]/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#37 /var/www/[HOST]/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#38 {main}