How to limit content types for a given page type in the job manager

Experience Manager (XPM) (UI Update for SDL Tridion 2011 SP1) allows administrators to create page types that contain component presentations, like pages, but also add rules on how to create and allow additional types of content.

For this type of page, I would like to simplify the author’s options by limiting the choice of content type.

I understand that we can:

  • Restrict content types so that authors can create only certain predefined content types for a given page type
  • In My Account, completely restrict the above to only predefined content types without selecting Content Types Already Used on the Page
  • Use areas that define combinations of patterns and patterns , as well as quantity limits. Authors can add (drag-and-drop) certain types and quantities of components to this region. For example, we can output the following in Staging to create an area:
 <div> <!-- Start Region: { title: "Promos", allowedComponentTypes: [ { schema: "tcm:2-42-8", template: "tcm:2-43-32" }, ], minOccurs: 1, maxOccurs: 3 } --> <!-- place the matching CPs here with template logic (eg TemplateBeginRepeat/ TemplateBeginIf with DWT) --> </div> 
  • Authors may still see components that they may want to insert (image below), but will not be able to add them if regions control the valid
  • However, folder permissions may reduce what component authors can see / use in the Insert Content library

Insert content

I got them all? Any other ways to use XPM functions or possible extensions to consider how to limit the allowed content for a given page type?

+6
source share
1 answer

Alvin, you pretty much provided most of the options in your question. Another option, if a special error message is required, or an even more subtle level of control, is to use an event system. Subscribe to the page save event. Initiated phase and write some verification code that throws an exception if there is an unwanted presentation of the component on the page.

Since the page types are really a combination of the page template, any metadata on the page and the types of presentation of the components on the page, we will need to check that we are dealing with the desired page type and if we meet a CP that does not match the desired one, we can just throw an exception . Here is a little code:

 [TcmExtension("Page Save Events")] public class PageSaveEvents : TcmExtension { public PageSaveEvents() { EventSystem.Subscribe<Page, SaveEventArgs>(ValidateAllowedContentTypes, EventPhases.Initiated); } public void ValidateAllowedContentTypes(Page p, SaveEventArgs args, EventPhases phases) { if (p.PageTemplate.Title != "My allowed page template" && p.MetadataSchema.Title != "My allowed page metadata schema") { if (!ValidateAllowedContentTypes(p)) { throw new Exception("Content Type not allowed on a page of this type."); } } } private bool ValidateAllowedContentTypes(Page p) { string ALLOWED_SCHEMAS = "My Allowed Schema A; My Allowed Schema B; My Allowed Schema C; etc"; //to-do put these in a parameter schema on the page template string ALLOWED_COMPONENT_TEMPLATES = "My Allowed Template 1; My Allowed Template 2; My Allowed Template 3; etc"; //to-do put these in a parameter schema on the page template bool ok = true; foreach (ComponentPresentation cp in p.ComponentPresentations) { if (!(ALLOWED_SCHEMAS.Contains(cp.Component.Schema.Title) && ALLOWED_COMPONENT_TEMPLATES.Contains(cp.ComponentTemplate.Title))) { ok = false; break; } } return ok; } } 
+4
source

All Articles