Question

Is there a way to differentiate between the Create and Edit of the Editor when serving up Shapes in Orchard CMS?

Perhaps this is something that could even be done at the Placement.info level?

Basically I have a ContentType that uses an Autoroute Part to set the permalink of that entity. I don't want people to be able to edit it after the initial creation, so it would be great to hide the part when in actual Edit mode - but have it visible and available when on the first "Create" page

Was it helpful?

Solution

Is there a way to differentiate between the Create and Edit of the Editor when serving up Shapes in Orchard CMS?

Not unless the module has been specifically written to do so. If you look at AutoroutePartDriver you'll see that it always returns a shape called Parts_Autoroute_Edit, so in this case it's not possible using Placement.info.

One thing you might not have seen is that the Autoroute part has two settings visible from the content type edit page (e.g. ~/Admin/ContentTypes/Edit/Page):

  • Allow custom patterns
  • Automatically regenerate when editing content

Unchecking both of these will prevent editing of the route once the content item has been created, however you won't be able to edit it when creating the content item either, instead you will have to rely on the generated slug. You will end up with reasonable slugs if you use a pattern like {Content.Slug}, or if you have your own deterministic way of generating a slug based on a content type then create a module that implements ITokenProvider and create your own token which uses your algorithm.

If you absolutely have to have the behavior as described in your question, then you could create a module which which suppresses the current AutoroutePartDriver (using OrchardSuppressDependency), but also inherits from it. You can then go on to override one of the Editor(...) methods to intercept when the editor shape is generated, or when the item is saved. You can use part.ContentItem.Id == 0 to see if you are dealing with a new content item or not. The big caveat with this approach is that it is dependent on the implementation of AutoroutePartDriver, so if that changes your driver might break.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top