How to change value of hidden field on node publish? My client has a system in which they allow nodes of certain content types to be created by authenticated users. The nodes are unpublished until they are reviewed by someone with the proper role and this all works correctly.

One of the requirements was allowing users to save a node as draft. I initially used the Save Draft module but found that was defaulting nodes to be published which caused problems. I worked around this by adding a hidden field called status that would change values based on which submit button was clicked via hooks. 

Now, the issue comes when the node is reviewed. At that point, an admin will change the node to published. They would also like automatically like this hidden status field to change from "submitted" to "published". Normally, I would use a hook for this but through my testing, I can't seem to get form alter hooks to work in the admin section.

I suppose I have two questions here:


Is there an easier way to achieve my end result here?
Failing that, is there a way to automatically change the value of one field when a node is updated via the admin section?
Piece of cake, if you are willing to use the Rules module for this ... like so:


Rules Event: before saving content, which covers all variations of updates of nodes, and creations of new nodes (and does not require an explicit "entity save" action).
Rules Conditions:


Entity has field, for your hidden status field, that way the logic implemented via this rules only applies for nodes that use this field.
Node-unchanged has status unpublished.
Node-changed has status published.

Rules Action: Set a data value, for your hidden status field, to assign the value 'published'.


With the above in mind, have a look at this rule (in Rules export format), in which I'm using a status field with machine name field_status (and for which a value of "P" reflects "Published" status:

 "rules_change_value_of_hidden_field_on_node_publish" : {
    "LABEL" : "Change value of hidden field on node publish",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_status" } },
      { "NOT node_is_published" : { "node" : [ "node-unchanged" ] } },
      { "node_is_published" : { "node" : [ "node" ] } }
    ],
    "DO" : [
      { "data_set" : { "data" : [ "node:field-status" ], "value" : "P" } }
    ]
  }
}


If you adapt the machine name field_status to match your own field's machine name, together with the value used to reflect "Published" status, you should be able to import the above rule in your own site. After doing so ... you should be done!