Cannot override publish on time in hook_form_alter

Created on 12 July 2024, 4 months ago
Updated 20 July 2024, 4 months ago

I need to override the "publish on" value on the node edit screen but if the node already has a publish on value, the time value won't change.

I tried modifying the scheduled publish on value using this line in hook_form_alter. For a node with an existing publish on value, this will successfully change the date but the time value won't change. However, if you inspect the time field, it shows my custom value but the frontend shows the original value (see screenshot).

$form['publish_on']['widget'][0]['value']['#default_value'] = new DrupalDateTime('2024-07-25 11:44:00 America/New_York');

If the node does not have a publish on value, the line above successfully changes/sets the date & time.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States todea

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

Comments & Activities

Production build 0.71.5 2024