I would like to ask about some ideas about following issue:
I have a content type - answer, that can be created and edited (not deleted) by users. From time to time, for any reason an user can delete all text inside node, thus completely destroying it.

I do not want to be informed about every subtle change in node, but I certainly want to be alerted and possibly approve, if there is a major change in node's content.

So the requirements are:

  • detect negative change + restrict user to publish changes + alert admin for approval


1) Count words in node and compare it to word count in node's revision. The word count may be saved inside a field in node and after compared by rules.

2) As suggested by @T-34, use custom module I found some modules but none of them gives the ability to figure out the difference percentage and use it with rules:
https://drupal.org/project/trevi - suggested by @T-34 gives me an error + it seem s to work only on node edit page.
Thank you for ideas.


I would use Diff and implement hook_entity_diff() (see diff.api.php), which allows modules to provide a comparison about entity properties.

Here you go:

function MYMODULE_entity_diff($old_entity, $new_entity, $context) {
  if ($context['entity_type'] == 'node') {
    $old_body = $old_entity->body[LANGUAGE_NONE][0]['value'];
    $new_body = $new_entity->body[LANGUAGE_NONE][0]['value'];
    $matching = similar_text($old_body, $new_body, $percent);
    $results['line'] = array(
      '#name' => t('Body'),
      '#old' => 'Number of matching chars: ' . $matching,
      '#new' => 'Percentage difference: ' . $percent,
    return $results;
| improve this answer | |
  • I edited question a bit. Thank you for code, I need drupal to react somehow based on the number. Best would be rules. This module gives a message with percentage number right? – loparr Jun 17 '14 at 0:01
  • Then you just need to add rules implementation. If you are not a programmer, you can hire someone to write this functionality for you - it will take not much time. – quotesBro Jun 17 '14 at 9:52
  • With code above you can see percentage number on page node/NID/revisions by clicking "compare" button, provided by Diff. – quotesBro Jun 17 '14 at 9:55

After I wrote my first answer, I found module https://drupal.org/project/trevi. It seems to be unsupported, but description says that this module has Difference percentage review method. You can try this module too.

| improve this answer | |
  • Hi, I tried this module before but it seems to work only on node edit page. – loparr Jun 16 '14 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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