Where does the $node get its field values after a node edit page has been submitted? I'm attempting to debug a problem where a date field is not being saved.

The field renders fine with the rest of the node form, but upon submit one particular field has no value.

The $form_state contains the expected value all the way down until the form does a redirect to the node view, however, in hook_node_presave, all the data that should be on the node, is missing.

I'm getting lost in the form api trying to trace down where exactly the form_state gets added onto the node.

I am using Drupal 7, and the Date module version 7.x-2.5.
It looks like the actual work to attach the fields to entity objects is done in the _field_invoke() function, right at the bottom with these lines:

if ($items !== array() || isset($entity-&gt;{$field_name}[$langcode])) {
  $entity-&gt;{$field_name}[$langcode] = $items;
}


That doesn't make a lot of sense out of context so it's worth having a look at the whole code for the function.

The basic workflow is:


The node form submit handler calls field_attach_submit()
field_attach_submit() calls _field_invoke_default()
_field_invoke_default() calls _field_invoke()


The entity object is passed through all of those functions and once they're run all fields are attached to the object.

I know it's not much to go on but hope it helps.