Drupal 7 Node Expire module

By shane
Fri, 2014-08-29 08:58
Daily Dose of Drupal Episode #165

Share with Others

The Drupal 7 Node Expire module allows you to use the power of the Rules module to perform actions on nodes at a specific point in time (when the node "expires"). This is useful for things such as unpublishing your content after a certain amount of time, or removing your content from the front page after it's been published for a week. You can also create rules actions to send an email at a specific time to serve as a reminder to do something related to a node on your Drupal site. The power of rules allows you to use the Node Expire module to set useful times and react on those events.

In this episode you will learn:

  • How to install and configure the Node Expire module
  • How to configure the rules actions for the Node Expire module
  • What some example use cases are for using the Node Expire module

Hello everyone and welcome to another Daily Dose of Drupal. Today we’re on Episode Number 165 and we’re going to go over the Node Expire Module. I am Shane Thomas, you can follow me on Twitter @smthomas3, also make sure to head over to codekarate.com and click on the link over here to learn a little bit about the EBook called “The 5 Secrets to Becoming a Drupal 7 Ninja” and take a look at that. But let’s go ahead and get started.

The Node Expire Module, it allows you to basically set a timer on your nodes and when that timer goes off or when that node is unexpired, then you can run specific rules, actions. This is useful if you want to unpublished node after a set amount of time, if you want to remove it from the front page or if you want to do something like send an email to the author. A whole bunch of different things.

You really have the power of rules to do whatever you want with that node when it expires. So we’re going to go ahead and take a look. You’re going to make sure you’re going to need the Rules Module downloaded and installed on your site. As you can see Rules and Rules UI has been turned on. You’ll also need the Date Module, well you actually don’t need this but if you want to be able to use the date pop-up rather than using a text field, you will need the date popup module. And that just comes with date, so turn on the date and date popup modules in the list. And then you will of course need the Node Expire Module and you’ll need to turn that on.

Once the Node Expire Module is turned on, we’re going to go ahead and configure this module. You can select how you want to handle it. I’m going to go ahead and just ignore the legacy mode but the first option that you might want to look at is to run the Content Expired Event every Kron run. So this means every time Kron runs after a node has been expired, the content event will run for that node.

The other option that we’re going to look at is to trigger the Content Expire Event only once when the node is expired. In this case it’s only ever going to trigger one time and we’re going to go ahead and leave that options. We’re going to select a date popup rather than a text field just to make it a little easier. And we’re also going to check this box to allow expire date in the past and that’s just going to let us move the demo along a little bit faster. So we can actually set the date in the past and see it’s working. So we click save.

The next step is to set up what we want our rule to do so I’m going to go into configuration workflow rules and I’m going to go ahead and add a new rule. If you’re not familiar with rules, check out some of the other Daily Dose of Drupal videos on configuring the Rules Module and how to use the Rules Module. We’re going to give this content a name of content as expired. This could be whatever you want it to be just so you know what it’s doing.

The event is the important part here and you’re going to see there’s an option called Content Expired. This didn’t exist before we installed the Node Expire Module. Let’s go ahead and select that and click Save. And now you have Rules that you can set up your actions to do whatever you want. So as I said before, if you wanted to unpublished the node, if you wanted to send an email, you can do all that kind of stuff using rules.

We’re going to remove the content from the front page in this example and we’re going to go ahead and select save. And our goal here is to have an article and set an expiration date and after so long we want that article to no longer show up on the front page. So this shouldn’t help us accomplish that. The next step is going to be turning the node expiration on for a content type.

As I mentioned before we want to use articles so we’re going to click Edit on the Article Content type. We’re going to head down to the publishing options and to check the box next to Enable Node Expiry. We can set a default expiration time. This uses the PHP String to time format so it’s pretty flexible in what you can do. I’m going to set a default of plus 30 days and this means anytime you create a node and you want it to expire, it’s going to default to 30 days out.

You can also set the expiration date limit, you can set if you want it to be required or not required. So we’ll click Save Content Type and we will now look at one of these specific articles. We’ll go ahead and select Test Article 2 and we will edit this article. Everything looks pretty much the same except now in this publishing options section, you have an expiration date. You can notice that it is set to 30 days out but we’re going to go ahead and change that to Yesterday, as you can see it’s the 14th and we can set it to the 13th. So we’re going to go ahead and click Save. If we come back to our homepage you’ll notice the article is still there.

However, as soon as we run cron and we come back to the homepage and refresh. You’ll notice that the article 2 is no longer in the front page. If you take a look at article 2 here you will see that the promote it to front page option is no longer checked. So if we check that just to show that I can get it back, it’s back on the front page. However if we run cron again, it’s not going to go away anymore because we specify the option to only run the Node Expiration event once with this article. So you can see we refresh the page, Test Article 2 will still going to be there.

So that’s really all there is to the Node Expire Module. You can do a whole bunch of thing with it. You can use rules to really react on that event however you want and perform a whole bunch of cool actions. So go ahead and give the module a try, let me know what you think. Make sure to check out all the content, the EBook and a whole bunch of other and blog post on codekarate.com and follow me on Twitter @smthomas3. Thanks for watching and we’ll see you next time.