News mover

  0 rating
11/13/2012 2:01:05 AM
4/17/2015 1:40:32 PM
Source: GitHub
Provider: Sitecore


The NewsMover project provides an event handler to relocate items based on a date field.


  • Documentation > Getting Started with the News Mover
    Getting Started with the News Mover

    You can use NewsMover to automatically relocate news articles based on an article release date.


    NewsMover adds a handler to the item:saved event. When the user creates or saves a news article, if a date field in the item is empty, NewsMover sets that field to the current date. If the path to the item (such as /news/article) does not match the value of that date field (for example, /news/2010/June/24/article), NewsMover creates the required path and moves the news article to that path.

    Sitecore fires the item:saved event for all items in all databases, but the NewsMover ignores events in databases other than Master.

    Sitecore might not fire the item:saved event for events such as move and duplicate.

    Data changes within the event handler, such as moving an item, populating the ReleaseDate field, and setting the sort order could raise nested item:saved events. To avoid infinite recursion, NewsMover manages a static list of the events its processing and ignores item:saved events on those items.

    You can create a data template, add the required code to your project, and update configuration manually, or you can install NewsMover from a package.

    Ensure that renderings allow Page Editor users to easily access news articles after creation.

    The News Article Data Template

    Create a data template for news articles containing a field of type Datetime. For this example I used field named ReleaseDate in the User Defined/NewsArticle data template.

    Optionally, create data templates for year, month, and day items. For this example, I used the Common/Folder data template for years, months, and days.

    The Sitecore.Sharedsource.Tasks.NewsItemHandler Class

    The Sitecore.Sharedsource.Tasks.NewsItemHandler class contains all of the logic for the NewsMover in a single item:saved event handler.

    Note: To compile this class, the Visual Studio project must reference the System.ServiceModel assembly.

    The item:saved Event Handler

    The OnNewsDateEvent() method handles the item:saved event. The logic of this handler is basically:

        1. Validate parameters and populate properties.
        2. Ignore items that are not news articles, news articles in irrelevant databases, the standard values item for the news article data template, and items in the list of items the event handler is already processing.
        3. Add the saved news item to the list of items that the event handler is already processing, to avoid infinite event recursion.
        4. Set the value of the DateField of the saved item to the current date and time, if that field does not already have a value, and if required, updates the sort order to reflect that date.
        5. Creates the path including year and optionally month and day, and moves the news item if required.
        6. Removes orphaned paths.
        7. Refreshes the content tree in the Content Editor.

    The Event Handler Definition

    In the web.config file, add a <handler> for the /configuration/sitecore/events/event named item:saved and set properties as required for your solution.

    <event name="item:saved">
      <handler type="Sitecore.Sharedsource.Tasks.NewsMover, Sitecore.Sharedsource.NewsMover" method="OnNewsDateEvent">
        <articletemplate>user defined/newsarticle</articletemplate>

    The event handler exposes several properties:

        * Database: The name of the database in which to handle events (required).
        * YearTemplate: The relative path to the data template to use to create year items (required).
        * MonthTemplate: The relative path to the data template to use to create month items (optional).
        * DayTemplate: The relative path to the data template to use to create day items (optional).
        * ArticleTemplate: The data template for news articles.
        * DateField: The name of the field in the news article that contains the release date.

    Version 1.0.1 available in the Branch

    Version 1.0.1 extends the module by moving the code that executes the client side refresh into a pipeline.

            <processor type="Sitecore.Sharedsource.NewsMover.Pipelines.RefreshContentTree, Sitecore.Sharedsource.NewsMover" />

    This can be used to add additional pipelines in the newsMover section to further refine how the module should perform.

    Version 2.0 available in the Trunk

    Version 2.0 extends the module by supporting the moving of items based on multiple templates. It has also been enhanced with configurable sorting and folder name Format Strings.

        <event name="item:saved">
            <handler type="Sitecore.Sharedsource.Tasks.NewsMover, Sitecore.Sharedsource.NewsMover" method="OnItemSaved">
              <templates hint="raw:AddTemplateConfiguration">

                Define a template configuration.
                  @id: [required] Any item based on the configured template will be ogranized
                  @sort: [optional] How to configure the sorting of 'folders' and the item (Ascending, Descending, null)
                    DateField: [required] The field on the template where the date is set
                    YearTemplate: [required] The template to use for creating year 'folders'
                    MonthTemplate: [optional] The template to use for creating month 'folders'
                    DayTemplate: [optional] The template to use for creating day 'folders'
                    @formatString: [optional] The Year/Month/Day nodes support this attribute.
                                              It will control how to format the date for the name of item
                                              defaults - yyyy/MM/dd for year, month, day nodes respectivley
                <template hint="1" id="user defined/newsarticle" sort="Descending">
                  <YearTemplate formatString="yyyy">Common/Folder</YearTemplate>
                  <MonthTemplate formatString="MMMM">Common/Folder</MonthTemplate>
                  <DayTemplate formatString="dd">Common/Folder</DayTemplate>

                <template hint="2" id="user defined/event" sort="Ascending">
                  <YearTemplate formatString="yyyy">Common/Folder</YearTemplate>
                  <MonthTemplate formatString="MMMM">Common/Folder</MonthTemplate>
                  <DayTemplate formatString="dd">Common/Folder</DayTemplate>

Release notes
The module was added 23-06-2010
Read more Back
Code examples

Solution screenshots(0)


Reviews (0)

Sort by: Date Most votes
  • Profile Avatar

    Level: 0

    x0 x0 x0




    Was this helpful?


Comments (0)

Sort by: Date  Most votes

Leave a Comment

Comment must be field in
Post comment

Write a review

Title can't be empty
Review can't be empty
Post review


Title Description Download Action

Add File