TypeError: DateTime::createFromFormat(): Argument #2 ($datetime) must be of type string

Created on 1 July 2022, almost 2 years ago
Updated 8 December 2023, 7 months ago

Problem/Motivation

The following PHP error appears in our logs when I go to the "create a user" form as an admin and enter a password in the Password field. A possible clue is that the password criteria for Fail/Pass will not update either. When I have uninstalled the Password Policy module, the error cannot be reproduced and the log is clean. I tried to find existing issues on this error but couldn't find one. Apologies if this is a duplicate somewhere.

TypeError: DateTime::createFromFormat(): Argument #2 ($datetime) must be of type string, array given in DateTime::createFromFormat() (line 251 of /var/www/html/docroot/core/lib/Drupal/Component/Datetime/DateTimePlus.php)

Steps to reproduce

Update: I found the issue -- on our site we had a paragraph entity (with a date field) that had an instantiated item in the add user form, but was not filled out. When I clicked "Remove" on the paragraph item, and filled out the Password field, all the Password Policy criteria was updated to the appropriate pass or fail status/and no error in log.

Alternatively, when I filled out the Paragraph item (including the date field on the paragraph) in the user form, and then filled out the Password field, the Password Policy criteria was updated to the appropriate pass or fail status/no error in log.

  • Environment is PHP 8
  • I am using 8.x-3.1 version of the Password Policy module, but have reproduced on the latest dev version and older ones
  • I have tested on both 9.3.14 and 9.4.1 versions of Drupal
  • Go to add user form at /admin/people/create
  • Enter a value in the Password field -- Ajax spinner will spin and then stop
  • Note: The Pass/Fail criteria for passwords will not update either, seeming to suggest Ajax is failing?
  • Go to logs, for my local we have db log at /admin/reports/dblog
  • For us, we now have the above PHP error

The full error is:

Location: /admin/people/create?_wrapper_format=drupal_ajax&ajax_form=1

TypeError: DateTime::createFromFormat(): Argument #2 ($datetime) must be of type string, array given in DateTime::createFromFormat() (line 251 of /var/www/html/docroot/core/lib/Drupal/Component/Datetime/DateTimePlus.php)
#0 /var/www/html/docroot/core/lib/Drupal/Component/Datetime/DateTimePlus.php(251): DateTime::createFromFormat()
#1 /var/www/html/docroot/core/modules/datetime/src/DateTimeComputed.php(57): Drupal\Component\Datetime\DateTimePlus::createFromFormat()
#2 /var/www/html/docroot/core/lib/Drupal/Core/Field/FieldItemBase.php(140): Drupal\datetime\DateTimeComputed->getValue()
#3 /var/www/html/docroot/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php(33): Drupal\Core\Field\FieldItemBase->__get()
#4 /var/www/html/docroot/core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php(59): Drupal\datetime_range\Plugin\Field\FieldWidget\DateRangeWidgetBase->formElement()
#5 /var/www/html/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(353): Drupal\datetime_range\Plugin\Field\FieldWidget\DateRangeDefaultWidget->formElement()
#6 /var/www/html/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(220): Drupal\Core\Field\WidgetBase->formSingleElement()
#7 /var/www/html/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(111): Drupal\Core\Field\WidgetBase->formMultipleElements()
#8 /var/www/html/docroot/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(181): Drupal\Core\Field\WidgetBase->form()
#9 /var/www/html/docroot/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php(663): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm()
#10 /var/www/html/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(353): Drupal\paragraphs\Plugin\Field\FieldWidget\InlineParagraphsWidget->formElement()
#11 /var/www/html/docroot/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php(843): Drupal\Core\Field\WidgetBase->formSingleElement()
#12 /var/www/html/docroot/core/lib/Drupal/Core/Field/WidgetBase.php(111): Drupal\paragraphs\Plugin\Field\FieldWidget\InlineParagraphsWidget->formMultipleElements()
#13 /var/www/html/docroot/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php(962): Drupal\Core\Field\WidgetBase->form()
#14 /var/www/html/docroot/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(181): Drupal\paragraphs\Plugin\Field\FieldWidget\InlineParagraphsWidget->form()
#15 /var/www/html/docroot/core/lib/Drupal/Core/Entity/ContentEntityForm.php(121): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm()
#16 /var/www/html/docroot/core/modules/user/src/AccountForm.php(309): Drupal\Core\Entity\ContentEntityForm->form()
#17 /var/www/html/docroot/core/modules/user/src/RegisterForm.php(53): Drupal\user\AccountForm->form()
#18 /var/www/html/docroot/core/lib/Drupal/Core/Entity/EntityForm.php(106): Drupal\user\RegisterForm->form()
#19 [internal function]: Drupal\Core\Entity\EntityForm->buildForm()
#20 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(531): call_user_func_array()
#21 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(370): Drupal\Core\Form\FormBuilder->retrieveForm()
#22 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(628): Drupal\Core\Form\FormBuilder->rebuildForm()
#23 /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm()
#24 /var/www/html/docroot/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#25 /var/www/html/docroot/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php(39): Drupal\Core\Controller\FormController->getContentResult()
#26 [internal function]: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
#27 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#28 /var/www/html/docroot/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#29 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#30 /var/www/html/docroot/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#31 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#32 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#33 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#34 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#35 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#36 /var/www/html/docroot/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#37 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#38 /var/www/html/docroot/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle()
#39 /var/www/html/docroot/index.php(19): Drupal\Core\DrupalKernel->handle()
#40 {main}

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States JackG102 Falls Church, VA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia 2pha

    I have the same problem, but in my case, it is because of a profile which had a required date field in it, and this profile field needed to be filled out when creating a user.
    If I selected a value for the date field before setting the password, it was fine. But if I tried settings the password when the date field did not yet have a value, I got the ajax error "TypeError: DateTime::createFromFormat(): Argument #2 ($datetime) must be of type string"

  • Status changed to Closed: works as designed 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States JackG102 Falls Church, VA

    After reading through the comments and having had the community respond -- this seems like an issue present elsewhere rather than the Password Policy module itself. I'll close the issue for now and mark it as "Closed works as designed". Thank you for the input and solutions all around!

Production build 0.69.0 2024