can't save value with date field...

Created on 31 October 2023, about 1 year ago

Problem/Motivation

Add date Field to entity content by example, it can't save data

Proposed resolution

module use this code

  $submission = $form_state->getFormObject()->submitForm($form,$form_state);
    $entity = $form_state->getFormObject()->getEntity();
    $entity->save();

to save form data but some field widgets need to convert value by widget method massageFormValues to normalized values
$entity->save() just saves value to database with array like this field_date =>['value' => '2023-01-01']
but the date field has format value like this field_date =>['value' => ['date' => '2023-01-01']];
it will show error
Warning: Array to string conversion in Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema::castValue() (line 2579 of D:\www\drupal10\web\core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema.php)

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France lazzyvn paris

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

Comments & Activities

Production build 0.71.5 2024