Views: 3390
Number of votes: 5
Average rating:

Introducing EPiServer PageTypeExtensions v1.0

A few months ago I was working on a project that had the requirement to restrict the number of pages of specific types that could be created beneath a page of a specific type.

I also had a need to not allow any pages under a page type.  But EPiServer currently doesn’t support this.  If you don’t explicitly select available page types then all page types will be available.

A couple of weeks ago I decided to revisit the code I wrote for this and make it available via an open source project.

The restrictions were enforced by hooking into DataFactory events such as creating, moving, saving, and publishing pages.

I decided to enhance the functionality and create a new version of the NewPage.aspx page.  This page would filter the available page types by checking the various configured restrictions.

After I implemented the necessary functionality for page type restrictions I recalled a blog post David Knipe wrote a year ago about enhancing the Create New Screen.  I thought while I was on the subject of building something that replaces the Create New page I could bolt in some thumbnail and preview image functionality.

Setup and Installation

Please refer to this document for detailed instructions on setup and usage.  The runtime binaries and source code can be downloaded from codeplex.

Features

Below I will give a quick summary on the features available and how to use them.  Please refer to this document for more detailed instructions on how to use the features available.

Page Type Restrictions

The page type restrictions functionality is dependent on PageTypeBuilder and allows a developer to restrict page types that can be created under particular page types.  The rules can be setup by decorating page type classes with PageTypeRestriction attributes.  Examples are below:

1. Specify that no children can be created under a page type named “Parent”.

[PageTypeRestriction(NumberOfAllowedChildren = 0)]
public class Parent : TypedPageData

2. Specify that a total of 5 pages can be created under a page type named “Parent”.

[PageTypeRestriction(NumberOfAllowedChildren = 5)]
public class Parent : TypedPageData

3. Specify that no instances of a page type named “Child” can be created under a page type named “Parent”.

[PageTypeRestriction(ChildPageTypeTypes = new[] { typeof(Child) }, NumberOfAllowedChildren = 0)]
public class Parent : TypedPageData

4. Specify that only 5 instances of a page type named “Child” and 1 instance of a page type named “ChildTwo” can be created under a page type named “Parent”.

[PageTypeRestriction(ChildPageTypeTypes = new[] { typeof(Child) }, NumberOfAllowedChildren = 5)]
[PageTypeRestriction(ChildPageTypeTypes = new[] { typeof(ChildTwo) }, NumberOfAllowedChildren = 1)]
public class Parent : TypedPageData

5. Specify that only 5 instances of a page type named “Child” and a page type named “ChildTwo” can be created under a page type named “Parent”.

[PageTypeRestriction(ChildPageTypeTypes = new[] { typeof(Child), typeof(ChildTwo) }, 
        NumberOfAllowedChildren = 5)]
public class Parent : TypedPageData

 

Thumbnail and Preview Images on Create New Page

This is a feature more people will probably be interested in.  There are many configuration settings that can be configured within the PageTypeExtensions.config file (please refer to usage instructions for more information) which allow you to configure thumbnail and preview images for the create new  page.

Put simply the new version of the create new page will get page type thumbnail and preview images from the VPP.

There is a scheduled job, an administration tool and right click tree view functionality which can be exploited to allow automatic generation of web page images.

Web page images are generated using IECapt but alternative capture tools/web services could be used by modifying the value of the webPageImageGeneratorType configuration attribute.

When creating images for page types, by default the last published page saved of a particular page type will be used for the image capture. It is possible to specify a particular page of a particular page type to use for the image capture. You can do this by adding a Boolean property to your page type with the same name as the value defined in the useForImagePreviewPropertyName configuration attribute. The editor then needs to set this property value to true on the page they want to use. If no page can be found with the property value set to true then the latest published save page will be used.

Examples of the updated NewPage.aspx which is used for creating pages from page types are shown below:

 

Feedback?

I am always eager to receive feedback good and bad. 

Please feel free to email or twitter me with any feedback @croweman or comment on the blog post Smile

Disclaimer

Although I have tested the assembly and am happy with it’s functioning there may well be little bugs that I have not spotted.  Please give it a thorough test before releasing it to the production environment and log any issues on codeplex.

Jun 17, 2011

Joshua Folkerts
(By Joshua Folkerts, 6/17/2011 6:25:23 PM)

Very nice.

toni
(By toni, 6/18/2011 2:12:26 AM)

Yes very nice! Maybe something you can incorporate with your tab-ordering Joshua?

Joshua Folkerts
(By Joshua Folkerts, 6/23/2011 6:00:57 AM)

Most certainly.

Please login to comment.