Drupal 6.25, CCK 2.9
I have a node of type EVENT. The EVENT node contains several CCK fields that allow users to submit events to our calendar which go in to a workflow. If the user requested IT support at their event, the IT support person is e-mailed. If they will be hosting an event with food, the catering staff is notified.
Everything works great except that we can edit the event later upon their request. If the edits that we make change one of these values that is used to notify staff, I need the system to automatically notify those people.
I know how to handle notification and everything else works well, but I don't know how to detect if the state of a single field is changing.
DETAILED EXAMPLE:
--- Event information... ---
Will you require IT support at your event?
- I need my lecture recorded.
- We will require someone on hand to assist with software installation.
- Video conferencing
- Special request
(multiple checkboxes)
--- More event information ... ---
If that EVENT node is submitted, approved, and later edited to change the value of that field so that one of the boxes is checked, I need to handle that.
I have a custom module to handle this in and have experience writing validation and submit handling, but I'm not sure what values of $form or $form_state are helpful to this task. I thought that I might store the value of the field as it was originally as a hidden field with a hook_form_FORM_ID_alter and then check that hidden value against the submitted value but it's hard to get CCK values in to hidden fields because you have to capture the value in an #after_build function and... I'm just getting stuck and thought I'd ask for help.
Thanks in advance for your time and consideration!
EDIT - My solution based on the suggestion from Jimajamma below:
function sitecustom_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
// If we are saving an EVENT node...
if ('presave' == $op && 'event' == $node->type) {
// If the node already exists...
if ($existing = node_load($node->nid)) {
// If the FIELD_EVENT_TECH_SUPPORT value has changed...
if ($node->field_event_tech_support == $existing->field_event_tech_support) {
// Log the change.
watchdog('event_edit', 'FIELD_EVENT_TECH_SUPPORT value did not change');
} else {
// Notify people accordingly.
// TODO: Notification of staff of changed tech support for EVENT.
// Log the notification.
watchdog('event_edit', 'Event edited with FIELD_EVENT_TECH_SUPPORT value changed. Staff notified.');
}
}
}
// Handle other nodeapi uses, validation, etc.
}
And I'm not exactly sure if it's correct to do if ($existing = node_load($node->nid))
because that block seems to execute even when an EVENT node is being created from scratch. I know that I could use if ($existing->created != $existing->changed)
but I haven't thought through everything yet and exactly what I want to test, etc. For now, using what I've shown above won't trigger the notification in this case IF the node is new.
I guess I just wanted to get something up here in terms of a solution in case people find this in the future. I will move on to exploring how to make this easier to do/find with RULES and ACTIONS as time allows.