TypeError: date(): Argument #2 ($timestamp) must be of type ?int, array given in date()

Created on 29 August 2023, over 1 year ago

Problem/Motivation

The following error appears in the error log/browser console when creating or editing a node with a new smart date field:

TypeError: date(): Argument #2 ($timestamp) must be of type ?int, array given in date() (regel 830 van /[..]/web/modules/contrib/smart_date/src/SmartDateTrait.php)

#0 /[..]/web/modules/contrib/smart_date/src/SmartDateTrait.php(830): date('H:i', Array)
#1 /[..]/web/modules/contrib/smart_date/src/SmartDateTrait.php(140): Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateFormatterBase::isAllDay(Array, Array)
#2 /[..]/web/core/lib/Drupal/Core/Field/FormatterBase.php(89): Drupal\smart_date\Plugin\Field\FieldFormatter\SmartDateFormatterBase->viewElements(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 'nl')
#3 /[..]/web/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php(265): Drupal\Core\Field\FormatterBase->view(Object(Drupal\smart_date\Plugin\Field\FieldType\SmartDateFieldItemList), 'nl')
#4 /[..]/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(339): Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array)

Steps to reproduce

  1. composer require drupal/core:10.1.2 drupal/smart_date:4.1.0-rc2
  2. Add a new date field to a node type.
  3. Add a new node or edit an existing one.
  4. The following error message appears: Oops, something went wrong. Check your browser's developer console for more details.
  5. When I check the failed AJAX request, I see the error as reported above.

Proposed resolution

I did a lot of debugging but I can't seem to find the root cause. This is the value which is passed as $start_ts and $end_ts argument:

Array
(
    [date] => 
    [time] => 
    [object] => 
)

It seems to come from Drupal\Core\Datetime\Element\Datetime::valueCallback().

🐛 Bug report
Status

Active

Version

4.1

Component

Code

Created by

🇧🇪Belgium dieterholvoet Brussels

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

Comments & Activities

Production build 0.71.5 2024