Hi,

There is an error when saving an alert you scheduled by setting only date (without hour).

InvalidArgumentException: The date cannot be created from a format. in Drupal\Component\Datetime\DateTimePlus::createFromFormat() (line 248 of core/lib/Drupal/Component/Datetime/DateTimePlus.php).

This patch add validateForm function to make control on date fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nicolas.hod created an issue. See original summary.

nicolas.hod’s picture

ChrisSnyder’s picture

Status: Active » Needs review
nicolas.hod’s picture

Sorry, my test was inclompete ...

When posting form with good values, I get an other error with my patch.

Drupal\Core\Entity\EntityStorageException: Entity validation was skipped. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

ChrisSnyder’s picture

Status: Needs review » Needs work
ChrisSnyder’s picture

Status: Needs work » Needs review
FileSize
881 bytes

It looks like the entity is trying create a date when no time is provided. The following patch should account for that.

ChrisSnyder’s picture

Title: Error when saving scheduled alert » Error when saving scheduled alert due to date validation
nicolas.hod’s picture

You're right. ;)

Just create a new patch by improving your test to prevent some warnings.

Thanks a lot.

nicolas.hod’s picture

A fix to my previous patch...

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Hello,
I tested the patch #9 and it seems to work as expected. At first, I was getting Warning: DateTime::createFromFormat() expects parameter 2 to be string, array given in Drupal\ error. But when I commented out the return on line 426 in src/Entity/SitewideAlert.php and refreshed the page everything was ok. When I removed the above comment everything was ok again and only received the errors The Start date date is invalid. I removed the module and cleared the cache and couldn't reproduce that warning again.

Thanks for the contribution,

kind regards, Denis

ChrisSnyder’s picture

Thanks for the fix nicolas.hod and thanks for testing DenisCi!

ChrisSnyder’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.