InvalidArgumentException: The timestamp must be numeric. in Drupal\Component\Datetime\DateTimePlus::createFromTimestamp

Created on 21 February 2025, about 1 month ago

Problem/Motivation

We have a smart_date field with unlimited cardinality and when we use the entity in a complex IEF (inline entity form), we get an error when adding another item to the widget:

#0 /var/www/html/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php(142): Drupal\Component\Datetime\DateTimePlus::createFromTimestamp(Array, '')
#1 /var/www/html/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateDefaultWidget.php(110): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#2 /var/www/html/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateInlineWidget.php(35): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateDefaultWidget->formElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#3 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(459): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateInlineWidget->formElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/html/web/modules/contrib/smart_date/src/Plugin/Field/FieldWidget/SmartDateWidgetBase.php(562): Drupal\Core\Field\WidgetBase->formSingleElement(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 0, Array, Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/html/web/core/lib/Drupal/Core/Field/WidgetBase.php(120): Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase->formMultipleElements(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), Array, Object(Drupal\Core\Form\FormState))
#6 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(197): Drupal\Core\Field\WidgetBase->form(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/html/web/modules/contrib/inline_entity_form/src/Form/EntityInlineForm.php(186): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object(Drupal\fedms_content\Entity\Session), Array, Object(Drupal\Core\Form\FormState))
#8 /var/www/html/web/modules/contrib/inline_entity_form/src/Element/InlineEntityForm.php(149): Drupal\inline_entity_form\Form\EntityInlineForm->entityForm(Array, Object(Drupal\Core\Form\FormState))
#9 [internal function]: Drupal\inline_entity_form\Element\InlineEntityForm::processEntityForm(Array, Object(Drupal\Core\Form\FormState), Array)
#10 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1010): call_user_func_array(Array, Array)
#11 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#12 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#13 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#14 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#15 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#16 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(1073): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#17 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(444): Drupal\Core\Form\FormBuilder->doBuildForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#18 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(625): Drupal\Core\Form\FormBuilder->rebuildForm('group_session_e...', Object(Drupal\Core\Form\FormState), Array)
#19 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm('group_session_e...', Array, Object(Drupal\Core\Form\FormState))
#20 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\group\Entity\Form\GroupForm), Object(Drupal\Core\Form\FormState))
#21 /var/www/html/web/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php(39): Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#22 [internal function]: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#23 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#24 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(593): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#25 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#26 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#27 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(183): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#28 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#29 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(709): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#40 {main}

From that stack trace, it looks like $items[$delta]->value in \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateWidgetBase::formElement is an array.

Proposed resolution

The code already checks if the property is not empty. It should also check if it contains a numeric value.

🐛 Bug report
Status

Active

Version

4.2

Component

Code

Created by

🇩🇪Germany jurgenhaas Gottmadingen

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024