array( 'type' => 'node', 'description' => t('Move parent event into a different workflow state'), 'configurable' => TRUE, 'hooks' => array( 'nodeapi' => array('update', 'insert', 'delete'), ), ), ); } function cv_relationships_update_parent_action($node, $context) { if ($node->field_engagement[0]['nid']) { $parent = node_load($node->field_engagement[0]['nid']); $comment = t($context['workflow_comment'], array( '%event_title' => check_plain($parent->title), '%state' => check_plain($context['state_name']), '%solicit_nid' => $node->nid, '%event_nid' => $parent->nid, )); workflow_execute_transition($parent, $context['target_sid'], $comment, $context['force']); // confirming if ($context['target_sid'] == 4) { $parent->field_confirmed_agency = $node->field_agency; $parent->field_confirmed_speaker[0]['uid'] = $node->uid; // confirming should clear emergency flags $admin = user_load($parent->field_uw_admin[0]['uid']); flag('unflag', 'emergency', $parent->nid, $admin); node_save($parent); } // back to processing. if this solicit was confirmed, reset the parent's // confirmed fields and flag it as an emergency else if ($context['target_sid'] == 3 && $node->_workflow == 13) { unset($parent->field_confirmed_agency[0]['nid']); unset($parent->field_confirmed_speaker[0]['uid']); $admin = user_load($parent->field_uw_admin[0]['uid']); flag('flag', 'emergency', $parent->nid, $admin); node_save($parent); } } } function cv_relationships_update_parent_action_form($context) { $form = array(); $result = db_query("SELECT * FROM {workflow_states} ws WHERE ws.sysid = 0 AND ws.wid = 1 ORDER BY ws.wid, ws.weight"); $previous_workflow = ''; $options = array(); while ($data = db_fetch_object($result)) { $options[$data->sid] = $data->state; } $form['target_sid'] = array( '#type' => 'select', '#title' => t('Target state'), '#description' => t('Please select that state that should be assigned when this action runs.'), '#default_value' => isset($context['target_sid']) ? $context['target_sid'] : '', '#options' => $options, ); $form['force'] = array( '#type' => 'checkbox', '#title' => t('Force transition'), '#description' => t('If this box is checked, the new state will be assigned even if workflow permissions disallow it.'), '#default_value' => isset($context['force']) ? $context['force'] : '', ); $form['workflow_comment'] = array( '#type' => 'textfield', '#title' => t('Message'), '#description' => t('This message will be written into the workflow history log when the action runs. You may include the following variables: %state, %event_title, %solicit_nid, %event_nid'), '#default_value' => isset($context['workflow_history']) ? $context['workflow_history'] : t('Action set %title to %state.'), ); return $form; } function cv_relationships_update_parent_action_submit($form_id, $form_state) { $state_name = db_result(db_query("SELECT state FROM {workflow_states} WHERE sid = %d", $form_state['values']['target_sid'])); return array( 'target_sid' => $form_state['values']['target_sid'], 'state_name' => $state_name, 'force' => $form_state['values']['force'], 'workflow_comment' => $form_state['values']['workflow_comment'], ); }