Password expiration sent field as number (integer) prevent password change

Created on 5 September 2024, 3 months ago

Problem

When the `password_policy_history` module is enabled we're still having problems with users trying to change their passwords. Something like this came up and was fixed before ( https://www.drupal.org/project/password_policy/issues/3465364 πŸ› Fatal error when changing password when password_policy_history is enabled RTBC ) but here the problem is that the form_state value of the `field_pending_expire_sent` field is not an array but rather a string, so when trying to extract the value in the WidgetBase class you get an error that prevents saving the form.

Specifically, the error is:

TypeError: Cannot access offset of type string on string in Drupal\Core\Field\WidgetBase->extractFormValues() (line 496 of /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php).

With this backtrace:

#0 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(244): Drupal\Core\Field\WidgetBase->extractFormValues()
#1 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(334): Drupal\Core\Entity\Entity\EntityFormDisplay->extractFormValues()
#2 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityForm.php(301): Drupal\Core\Entity\ContentEntityForm->copyFormValuesToEntity()
#3 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(155): Drupal\Core\Entity\EntityForm->buildEntity()
#4 /var/www/html/web/core/modules/user/src/AccountForm.php(373): Drupal\Core\Entity\ContentEntityForm->buildEntity()
#5 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityForm.php(286): Drupal\user\AccountForm->buildEntity()
#6 /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(145): Drupal\Core\Entity\EntityForm->submitForm()
#7 /var/www/html/web/core/modules/user/src/AccountForm.php(437): Drupal\Core\Entity\ContentEntityForm->submitForm()
#8 [internal function]: Drupal\user\AccountForm->submitForm()
#9 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array()
#10 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()
#11 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm()
#12 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm()
#13 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#14 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#15 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#16 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#18 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#22 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#23 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#24 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#25 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#26 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#27 /var/www/html/vendor/asm89/stack-cors/src/Cors.php(53): Drupal\page_cache\StackMiddleware\PageCache->handle()
#28 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Asm89\Stack\Cors->handle()
#29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#31 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#32 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#33 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#34 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#35 {main}

Workaround for now

I'm not sure if this is a core bug, but if I change the type of field to a boolean in configuration the form will save and the user password will be changed as expected. I plan to do more testing and work on this soon, but that's what I've found so far.

Changes:

field.field.user.user.field_pending_expire_sent.yml

settings:
  on_label: 'Pending expiration email sent'
  off_label: 'Pending expiration email not sent'
field_type: boolean

field.storage.user.user.field_pending_expire_sent.yml

type: boolean
settings: {  }
πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States beunerd Providence, Rhode Island

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

Comments & Activities

Production build 0.71.5 2024