2
votes

What I am trying to do is to enable/disable revision according to the selected taxonomy term in the content type that I have created i.e. when a user add the content the user can select the taxonomy term field(may be a select field) according to the selected option I want to enable/disable the revision. How can I do this?

1

1 Answers

3
votes

Turn off the create new revision setting for the content type.

Then in hook_form_alter add a new submission handler before the main one:

function YOUR_MODULE_form_alter(&$form, &$form_state, $form_id) {
    //drupal_set_message("Form ID is : " . $form_id);
    switch($form_id) {
        case 'CONTENT_TYPE_node_form':
            //dpm($form);
            $form['actions']['submit']['#submit'][] = 'revision_control_node_form_submit';
            $form['actions']['submit']['#submit'] = array_reverse($form['actions']['submit']['#submit']); // reverse array to put our submit handler first
            break;
    }

}

Then in the new submit handler check if the taxonomy term has the correct value to save a new revision. I've not tried this next bit but according to this page putting

$node->revision = 1;

before node save will create a new revision.

node_save is called in node_form_submit and the node object is built in node_form_submit_build_node.

Looking at the other attributes like vid that belong to $form_state I would say an good educated guess would be to put $form_state->revision = 1; and see if that comes out as a property of the node after node_form_submit_build_node.

So you final new submit handler will look something like:

function revision_control_node_form_submit($form, &$form_state) {
    if($form_state['values']['your_taxonomy_field'] == 'your_value') {
        $form_state->revision = 1;
    }
}

Now I've not actually tried any of this but even if it doesn't work I'm sure you will be on the right track... Good luck!