-
Notifications
You must be signed in to change notification settings - Fork 40
Description
Description of the bug
Editing an existing node with a date field that's hidden via '#access' => FALSE saves a null value to the database. This, in turn, produces notices when viewing the node: Warning: Trying to access array offset on value of type null in theme_date_display_combination() (line 219 of /Users/XXX/Sites/localhost/kmta/core/modules/date/date.theme.inc). This happens regardless of the widget [EDIT: the HTML5 widget handles this correctly].
Steps To Reproduce
In order to reproduce the problem, you have to alter the node_form to hide the date field.
- Add a field called
field_test_dateto the Page content type. Use any widget [EDIT: OTHER THAN HTML5] - Set the Default Valuie in the field UI to "No default value"
- In a custom module, implement
hook_form_node_form_alter(&$form, &$form_state); - In that hook, set the access to false, as in
$form['field_test_date'][LANGUAGE_NONE][0]['#access'] = FALSE; - Create a page node. Check the database table
field_data_field_test_date. Nothing is saved for the new node. 👍🏽 - Edit that same page node (no need to change anything). Click
Save
You'll get the notices above. If you inspect the table for the field you'll see a NULL value being stored. 👎🏽
Actual behavior
Null value gets saved for the date. Notices are thrown when viewing the node.
Expected behavior
Nothing should get saved, since the field is hidden and its default value is none.
Additional information
Add any other information that could help, such as:
- PHP 8.1
- Backdrop 1.25.1
I've tested the same in Drupal 7. As expected, D7 does not save a null value for the date, and therefore the notices are not produced