Using Diff

Learn how to compare revisions using the Diff module.

We’ll cover the following:

  • How to install Diff
  • How to compare revisions

Composer command

composer require drupal/diff

Transcript

Trainer (00:00):
In the previous video, you learnt about the revision system in Drupal. We looked at how to revert, delete and also view a revision, which can be done by clicking on the date and time on a specific revision. But one thing you cannot do is compare two revisions and see what’s changed. Luckily there’s a third-party module called Diff, which lets you compare revisions and see the differences. To learn about the module, just go to drupal.org/project/diff. Let’s start things off by downloading the module. So jump into your terminal and type in the following composer command, composer require drupal/diff. Now, let’s jump back into our Drupal site. And I’ll close this tab. And then, let’s go to extend. And then, search for Diff and instal the module.

Trainer (01:02):
Now that the Diff module has been installed, let’s make a few more changes to our product. So, let’s go back to content and let’s edit this top product. Let’s change the product summary and I’ll change this last word to “CHANGED”. I’ll change the price from 20 to $50. And let’s add in some body text. Then, scroll down and click on save. Now, let’s go to the revisions page. Now, this revisions page looks a little different once we installed the Diff module. Each revision has a radio button which allows us to select them. And we also have a new button called compare selected revisions. So to compare revisions, all we need to do is select them using the radio buttons. Let’s select the two most recent ones. And then, click on compare selected revisions.

Trainer (02:02):
And now, we can see the differences between the two revisions. Text which has been added has a green background and it’s underlined, and text which has been removed has a red background and a strikethrough it. Using the visual inline layout, we can switch between different view modes. Currently, we are viewing the default view mode. But if we change it to full content, we can now see the price because the price is displayed in the full content view mode. And we can also view the differences on the teaser view mode. From the layout dropdown, we can compare the differences using different layouts. Currently, this is the visual inline. But if we select split fields, this shows us the differences side-by-side. And if we change the layout to unified fields, it’ll show us the differences grouped by fields.

Trainer (03:05):
I personally like to use the split fields. I like to have the old version on the left and the new version on the right, but this is just a personal preference. Let’s take a look at some of the module settings. Go to configuration, and then click on Diff. From the layout setting, you can enable or disable layout options by simply checking or unchecking the checkbox. And you can also reorder the layout options by clicking on the toggle and moving them up or down. This is useful for when you want to give your Drupal users access to only one layout. And then if we click on the fields tab up the top here, you can control if a field should be compared or not. I’ve personally never changed these options. But if you’re having some trouble with comparing content, then play around with these options. So, that’s how you use the Diff module. If you are going to have revisions turned on, then I highly recommend that you install this module.

Scroll to Top