2

I am trying to disable the 'Create new revision option' in each existing nodes programmatically. I tried with below codes but it was not working.

$results = db_select('node', 'n')
->fields('n', array('nid','vid'))
->execute();
foreach ($results as $result) {
$node = node_load($result->nid);
// Disabling the Create new revision option
$node->revision = FALSE;
node_save($node);
}

Can anyone help me on this? Thanks.

4
  • are you using this module? drupal.org/project/revisioning
    – shrish
    Commented Jun 4, 2014 at 5:43
  • Do you want to remove revision option from node update form ?
    – Anil Sagar
    Commented Jun 4, 2014 at 5:45
  • 1
    @shrish I am not using this module.
    – Aswini K
    Commented Jun 4, 2014 at 5:50
  • @Anil I don't want to remove this option. I need to disable this option programmatically to some selected existing nodes.
    – Aswini K
    Commented Jun 4, 2014 at 5:55

2 Answers 2

3

Code you have mentioned in your question solves the problem of create new revision or just update with out a new revision when a node is updated programatically in that particular instance.. It has nothing to do with form option in node edit page...

When you do $node->revision = FALSE;

It is just like telling to node your are updating should be saved as a new revision or not when a node is updated at that particular instance of node_save...

Use hook_form_alter to disable this option in node edit page form..

in your custom module implement MODULE_form_alter and check for node id's you want to disable this option..

$form['revision_information']['#access'] = FALSE;

OR

$form['revision_information']['#disabled'] = TRUE;
2
  • Should it be $form['revision_information']['#disabled'] = TRUE;? Access FALSE, but disabled is TRUE.
    – AjitS
    Commented Jun 4, 2014 at 6:00
  • Yeah.. I have corrected.. :-)
    – Anil Sagar
    Commented Jun 4, 2014 at 6:01
2

Seems like you are not getting the correct data in the array $results

Try this,

    $results = array();
    $results = db_select('node', 'n')
    ->fields('n',array('nid','vid'))
    ->execute()
    ->fetchAll();
    foreach ($results as $result) {
    $node = node_load($result->nid);
    // Disabling the Create new revision option
    $node->revision = FALSE;
    node_save($node);
    }
1
  • 1
    Thanks shrish. It got worked by using the hook_form_alter.
    – Aswini K
    Commented Jun 6, 2014 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.