Skip to content

Hidden date field saves null values when editing an existing node, producing notices #6198

@argiepiano

Description

@argiepiano

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.

  1. Add a field called field_test_date to the Page content type. Use any widget [EDIT: OTHER THAN HTML5]
  2. Set the Default Valuie in the field UI to "No default value"
  3. In a custom module, implement hook_form_node_form_alter(&$form, &$form_state);
  4. In that hook, set the access to false, as in $form['field_test_date'][LANGUAGE_NONE][0]['#access'] = FALSE;
  5. Create a page node. Check the database table field_data_field_test_date. Nothing is saved for the new node. 👍🏽
  6. 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


PR backdrop/backdrop#4499

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions