Archive Later Feature, Notifications Feature - This week in Orchard (23/09/2022)

Gábor Domonkos's avatar
Localization, This week in Orchard, Module

Archive Later Feature, extract GetLanguageDirection() and IsRightToLeft() to CultureInfoExtensions, introduce EnabledByDependencyOnly flag for features to allow the feature's state to be auto, and a demo about a feature called Notifications! Check out our post for the details!

Orchard Core updates

Archive Later Feature

Back in 2020, we mentioned the Publish Later Feature which adds the ability to schedule content items to be published at a given future date and time. Now here comes the Archive Later Feature, which provides a way to unpublish content items at a given time. Let's see a simple example of the usage!

Open up the admin UI of Orchard Core and head to Configuration -> Features and enable the Archive Later module. If you would like to use this feature with your content type you have to edit its definition by attaching the Archive Later Part to it. Let's attach the Archive Later Part to the Blog Post content type! Now let's edit our predefined blog post!

Setting up the date for the Archive Later feature

At the bottom of the editor, you will see a new input Tag Helper with the datetime-local input type. If you set the date and the time here and hit the Archive Later button, the status of the current version will automatically change to draft when the time goes by using a background task. We also have a Cancel Archive Later button, so we can cancel the archiving process. And in the SummaryAdmin list, you also had a little message that shows you the date and time when the content item will be archived.

A content item which is scheduled to be archived

Extract GetLanguageDirection() and IsRightToLeft() to CultureInfoExtensions

We have some extension methods for CultureInfo to deal with language direction. These extension methods were placed in the LanguageDirection class and now they have their own class called CultureInfoExtensions. So, from now on you can find these extensions here. Small change but nice to have extension methods in a separate class.

The new CultureInfoExtensions class

Introduce EnabledByDependencyOnly flag for features to allow the feature's state to be auto

To represent this new change, we will use the features that you can check out in detail in the demo down below regarding the Notifications Feature. So, let's say you are on the Features page and search for the "notifications" word. Here you can find the Notifications module, which is only enabled if you enable one of its dependencies. So, you can't enable it right away. But the Email Notifications module requires it, meaning if you enable the Email Notifications module, the Notifications module will be enabled as well. And if you disable the Email Notification module, the Notifications module will be disabled as well because none of its dependencies are enabled.

Usage of the EnabledByDependencyOnly flag

And it's a flag that is very easy to use! If you open up the Manifest.cs file of the OrchardCore.Notifications module (can be found in this branch), you will see the feature with ID OrchardCore.Nofitications has this property set to true. It means that if we enable one of the dependencies of this feature, this module will be automatically enabled. And if none of the dependencies of this feature are enabled, then this module will be automatically disabled.

Using the EnabledByDependencyOnly flag

Demos

Notifications Feature

The Notifications Feature provides a way to be able to send notifications to notify users. You could implement a push notification to a mobile phone, you could implement a web notification, you can have an email notification, etc. For right now you can see the implementation of the email notification, and the Email Notifications module is the one that provides you with this feature. Let's enable it!

After that, we can edit one of the existing users on the site and say that we want to send email notifications to this user. And if you implement a push notification or a web notification, then you will see a flag for those as well and we can set up what kind of notifications we want to send to the given user.

User notification types

But this might feel incomplete without the Notification Templates feature which provides a way to create notification templates. Let's enable this one as well! And this will mean that now we can create new Notification Template content items. Let's create a new one and call it "Welcome email for new users template". We will send this email any time a new user is created. Here you can select the provider that you want to utilize, let's select the New user notification here. And as you can see, you have a subject and a body.

Creating a new user notification template

There are also username, password, and email arguments, that we automatically create because this provider is aware of them. It means you can inject these into the subject and the body of the email that you want to send. The idea here is if you create a new user as an admin you might want to send their temporary password in an email. Here you can use Shortcodes and Liquid templates as you can see.

So, we mentioned that we have a New user notification provider. If you enable the third notifications-related feature, called Notification Templates for Contents, it will give you more providers to use. So, if we create another Notification Template, now we can select the Content based notification provider too. It provides you with more templates (DisplayText, ContentItemId, ContentType, etc.) because it has more awareness. At the bottom, you can control who should be the person who receives this.

Creating a content based notification template

But here right now you don't have the way to select that I want to send out this notification when someone publishes the Article content type. So, selecting the content type and the event is not here. To do that, you have to edit the content definition of a given content type. If we select the Blog Post one, for example, you can see a new setting, called Notifications. If you select to send a notification, you can define which event you want to use and the given notification template.

Edit content definition to send events based notifications

This feature is a PoC and if you want to check out the implementation or try it out in your solution, you can find the code in this branch. And if you prefer videos, check out this recording on YouTube to see more about this feature!

News from the community

Orchard Dojo Newsletter

Lombiq's Orchard Dojo Newsletter has 350 subscribers! We have started this newsletter to inform the community around Orchard of the latest news about the platform. By subscribing to this newsletter, you will get an e-mail whenever a new post is published to Orchard Dojo, including This week in Orchard of course.

Do you know of other Orchard enthusiasts who you think would like to read our weekly articles? Tell them to subscribe here!

If you are interested in more news around Orchard and the details of the topics above, don't forget to check out the recording of this Orchard meeting!

No Comments

Add a Comment