I am writing a module for custom content type. And for the content type I am writing, revisions does not make sense. Is there a way to disable revisions (not allow users to create revisions) for my content type either programmatically (in my module code) or user permissions?

Thanks in advance.

Comments

raghukr’s picture

As usual, no help from drupal community. I have figured it myself.

I added the below code in hook_validate()

<?php
    if($node->revision)
        form_set_error('Revisions', t('Revisions not allowed'));
?>
madaerodog’s picture

adding this in template.php in your theme removes revisions for good

function phptemplate_node_form($form)
{
$form['revision_information']['#access'] = FALSE;
return theme_node_form($form);
}

don't forget to flush theme caches so you can see the results

extexan’s picture

@madaerodog...

Is there no place in Drupal to turn off revisions? If not, I find that hard to believe. Also, if not, where would I post a request for that feature?

[Update: never mind... I found it.] ;-)

Btw, is there a way for the owner of a post to delete it? As in... I would like to delete this one instead of leaving a useless post out there to be searched (and potentially wasting the time of others by reading it).

It's never too late to have a happy childhood. ;-)

LiveWire’s picture

Please share.

~ Mike Usry
SEO Firm

extexan’s picture

@musry7... You're so right. I should have posted the answer. Sorry for that omission.

Go to admin/content/types and edit the content for which you wish to turn off revisions. In "Workflow settings", uncheck "Create new revision". Simple, but hard to find. (I had to search a while to find it again myself.)

It's never too late to have a happy childhood. ;-)

kevin-bcr’s picture

Hi. Thank you helping. Is this in reference to Drupal 6? I cannot find "workflow settings" in Drupal 7.

Also, does this affect node revisioning at the node level? What if I want to stop the uploaded files from being revisioned with names like file.pdf, then file_0.pdf, then file_1.pdf?

Thank you!
Kevin

rar’s picture

Ditto - it doesn't appear to be a setting in Drupal 7. This "forward progress on new versions of Drupal" without also some breakdown or organization of documentation on D7 vs D6 vs D8 vs DX and expecting the community to pick up the pieces is a big dissapointment.

extexan’s picture

For D7... go to admin/structure/types/manage/[content-type]

Near the bottom, click "Publishing options"...

The bottom checkbox is "Create new revision"... uncheck to disable revisioning by content type.

It's never too late to have a happy childhood. ;-)

welly’s picture

No, that's incorrect. It sets the default action to create a new revision when you save changes to a node.

FoxRocK-1’s picture

Hello,

hope this help, you can disable it with a form alter hook.

function ldn_groups_form_node_form_alter(&$form, &$form_state, $form_id) {
  $type = $form['type']['#value'];
  
  if($type == 'group')
    unset ($form['revision_information']);
  
}
lcampanis’s picture

To remove the revisions from showing in the admin, just changed a bit the function given above to:

<?php
function phptemplate_node_form($form) {
	# disable revisions
	unset($form['revision_information']);
	
	return theme_node_form($form);
}
?>
AndrewBoag’s picture

I was also surprised that this wasn't easier. Still, that's why we write modules :-)

Here is a similar brutal approach using hook form alter.

This was really just a proof of concept (it works) - In an ideal world we want to check more about the form type - make sure that it's a node edit etc.

I think I might throw together a module that does this all in a better way and allows some per-node-type configuration.

function MODULE_NAME_form_alter(&$form,$form_state,$form_id) {
    //CAVEAT: there should be more checks here ....
    $form['revision_information'] = NULL;
}
ncdevman’s picture

For Drupal 8, go to /admin/structure/types/manage/[content-type-name]

and the checkbox is under the publishing options. 

sandip27’s picture

The only checked option under default options of Publishing is "Published". "Create new revision" is un-checked and still doesn't get rid off Revision Information checkbox (only checkbox but no textarea though) on node edit ! Cleared Cache, closed and again re-opened session still no luck.  The only role is 'authenticated user' in permissions and Authenticated User has only Add New Node for that specific content type set.  Nothing else.  I really, don't want to handle everything in code.  Any other suggestion please ?

jaypan’s picture

By default, the revisions option is only shown to users with permission to create/edit revisions. If you do not have this permission selected and the user is still seeing the revision checkbox, it means you have a module or theme that is altering Drupal core functionality. You'll need to figure out which module/theme that is and disable it.

Contact me to contract me for D7 -> D10/11 migrations.

sandip27’s picture

Hello Jaypan,

Thanks for the reply.  Well, my setup is pure Default out of box Drupal 8 Setup  (8.7.7 to be specific).  No contributed module or theme installed, so we're covered on that note as well. Only permission I changed is "Add xyz Type Content" and "Edit Own xyz Type Content" to the 'Authenticated User'. In fact I even removed all Default permissions provided by default and kept only these two permission to authenticated user and still no luck. On top of that 'Authenticated User' does not hold 'Administer content' permission so that's also covered. And I still see Revision related box at the bottom of Node Edit. 

I am lost now, and started regretting D8 for sure.  Was so pleased with D7 but D8 is really making me regret for its odd, unruly behavior.

Any help would be really appreciated. Thanks

jaypan’s picture

Are you logged in as the first user you get with the site? That user bypasses any permissions checks, so the permissions you select will not matter. 

Contact me to contract me for D7 -> D10/11 migrations.

sandip27’s picture

Well, No, not as a first user.  I am logged in as authenticated user and not administrator, user having uid = 3.  So this user must not see the revision form ideally.

t_d_d’s picture

Did you solved this? I have same problem. Revisions disabled, no permission for revisions for user role, yet users see checkbox to create a new revision when editing content. (Drupal 8.9.3)

htakamur’s picture

I have the same problem. In my case, the following css works:

.vertical-tabs {
display: none;
}