Address field mapping errors

Created on 29 November 2023, 12 months ago
Updated 14 May 2024, 6 months ago

Problem/Motivation

The address field mapping doesn't appear to function correctly when connecting a webform address field to a drupal address field. (D10.1.6) I have found Three failure modes.

If no default values are supplied $field_definition->getDefaultValue($content)[0]
of webform_content_creator/src/Plugin/WebformContentCreator/FieldMapping/AddressFieldMapping.php line 35 returns null and you fail to create the new entity and get a php error.

Message	Warning: Undefined array key 0 in Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMapping\AddressFieldMapping->mapEntityField() (line 35 of /var/www/docroot/modules/contrib/webform_content_creator/src/Plugin/WebformContentCreator/FieldMapping/AddressFieldMapping.php)
#0 /var/www/docroot/core/includes/bootstrap.inc(164): _drupal_error_handler_real(2, 'Undefined array...', '/var/www/docroo...', 35)
#1 /var/www/docroot/modules/contrib/webform_content_creator/src/Plugin/WebformContentCreator/FieldMapping/AddressFieldMapping.php(35): _drupal_error_handler(2, 'Undefined array...', '/var/www/docroo...', 35)
#2 /var/www/docroot/modules/contrib/webform_content_creator/src/Entity/WebformContentCreatorEntity.php(394): Drupal\webform_content_creator\Plugin\WebformContentCreator\FieldMapping\AddressFieldMapping->mapEntityField(Object(Drupal\node\Entity\Node), Array, Object(Drupal\field\Entity\FieldConfig), Array, Array)
#3 /var/www/docroot/modules/contrib/webform_content_creator/src/Entity/WebformContentCreatorEntity.php(437): Drupal\webform_content_creator\Entity\WebformContentCreatorEntity->mapContentField(Object(Drupal\node\Entity\Node), Object(Drupal\webform\Entity\WebformSubmission), Array, Array, '', 'field_address', Array, Array)
#4 /var/www/docroot/modules/contrib/webform_content_creator/webform_content_creator.module(25): Drupal\webform_content_creator\Entity\WebformContentCreatorEntity->createContent(Object(Drupal\webform\Entity\WebformSubmission))
#5 [internal function]: webform_content_creator_webform_submission_insert(Object(Drupal\webform\Entity\WebformSubmission))
#6 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(409): call_user_func_array(Object(Closure), Array)
#7 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(388): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'webform_content...')
#8 /var/www/docroot/core/lib/Drupal/Core/Extension/ModuleHandler.php(416): Drupal\Core\Extension\ModuleHandler->invokeAllWith('webform_submiss...', Object(Closure))
#9 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(215): Drupal\Core\Extension\ModuleHandler->invokeAll('webform_submiss...', Array)
#10 /var/www/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(900): Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object(Drupal\webform\Entity\WebformSubmission))
#11 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(564): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object(Drupal\webform\Entity\WebformSubmission))
#12 /var/www/docroot/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(781): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\webform\Entity\WebformSubmission), false)
#13 /var/www/docroot/modules/contrib/webform/src/WebformSubmissionStorage.php(1025): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\webform\Entity\WebformSubmission), false)
#14 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(489): Drupal\webform\WebformSubmissionStorage->doPostSave(Object(Drupal\webform\Entity\WebformSubmission), false)
#15 /var/www/docroot/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(806): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\webform\Entity\WebformSubmission))
#16 /var/www/docroot/modules/contrib/webform/src/WebformSubmissionStorage.php(983): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\webform\Entity\WebformSubmission))
#17 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\webform\WebformSubmissionStorage->save(Object(Drupal\webform\Entity\WebformSubmission))
#18 /var/www/docroot/modules/contrib/webform/src/Entity/WebformSubmission.php(913): Drupal\Core\Entity\EntityBase->save()
#19 /var/www/docroot/modules/contrib/webform/src/WebformSubmissionForm.php(2017): Drupal\webform\Entity\WebformSubmission->save()
#20 [internal function]: Drupal\webform\WebformSubmissionForm->save(Array, Object(Drupal\Core\Form\FormState))
#21 /var/www/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array(Array, Array)
#22 /var/www/docroot/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#23 /var/www/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#24 /var/www/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('webform_submiss...', Array, Object(Drupal\Core\Form\FormState))
#25 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\webform\WebformSubmissionForm), Object(Drupal\Core\Form\FormState))
#26 /var/www/docroot/modules/contrib/webform/src/Entity/Webform.php(1257): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\webform\Entity\WebformSubmission), 'add')
#27 /var/www/docroot/modules/contrib/webform/src/Controller/WebformEntityController.php(77): Drupal\webform\Entity\Webform->getSubmissionForm()
#28 [internal function]: Drupal\webform\Controller\WebformEntityController->addForm(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\webform\Entity\Webform))
#29 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#30 /var/www/docroot/core/lib/Drupal/Core/Render/Renderer.php(592): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#31 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#32 /var/www/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#33 /var/www/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#34 /var/www/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#35 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /var/www/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /var/www/docroot/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /var/www/docroot/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#40 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#41 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#42 /var/www/docroot/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#43 /var/www/docroot/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#44 /var/www/docroot/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#45 {main}

Changing line 35 to $field_value = $field_definition->getDefaultValue($content)[0] ?? []; gets you past that, however then you pop a sqlstate error because the module tries to shove an entire country name into the node's address field when it is expecting a two character value.

SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_address_country_code' at row 1: INSERT INTO "node__field_address" ("entity_id", "revision_id", "bundle", "delta", "langcode", "field_address_langcode", "field_address_country_code", "field_address_administrative_area", "field_address_locality", "field_address_dependent_locality", "field_address_postal_code", "field_address_sorting_code", "field_address_address_line1", "field_address_address_line2", "field_address_organization", "field_address_given_name", "field_address_additional_name", "field_address_family_name") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17); Array ( [:db_insert_placeholder_0] => 61606 [:db_insert_placeholder_1] => 270119 [:db_insert_placeholder_2] => nonprofit_detail [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => en [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => United States [:db_insert_placeholder_7] => Alabama [:db_insert_placeholder_8] => Alabama [:db_insert_placeholder_9] => [:db_insert_placeholder_10] => 35242 [:db_insert_placeholder_11] => [:db_insert_placeholder_12] => 123 Imaginary Ave [:db_insert_placeholder_13] => Address 2 [:db_insert_placeholder_14] => [:db_insert_placeholder_15] => [:db_insert_placeholder_16] => [:db_insert_placeholder_17] => )

Third, while you don't get a SQL error, the module tries to shove the webform's full "state_province" value into the "administrative_area" field. At least for the United States, this field in drupal is looking for the two letter state abbreviation. This means, on the next node edit, Drupal's field validator will prevent you from saving the node until you update this value to the correct format.

πŸ› Bug report
Status

Closed: works as designed

Version

4.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024