This project is read-only.

Properly save Autoroute and field data when creating item

Topics: Core, Writing modules
Apr 10, 2012 at 1:54 PM

Today I found the following pitfall:

When saving a new item that also has fields through a custom controller, the following criteria should be met:

  • For Autoroute to properly save the slug from the title the item has to be updated before creation (i.e. call _contentManager.UpdateEditor(item, this) before _contentManager.Create(item))
  • For fields to work properly the content item has to be created before updating (i.e. call _contentManager.Create(item) before_contentManager.UpdateEditor(item, this))

Now if I merge the two (

_contentManager.UpdateEditor(item, this);
_contentManager.UpdateEditor(item, this);
) field data is saved twice, into the ContentItemVersionRecord and ContentItemRecord as well (see this discussion and the linked issue).

This looks rather problematic, what would be the best practice?

Thanks in advance!

Apr 12, 2012 at 12:34 AM

I don;t understand what you are trying to do or why you are using a custom controller.

Apr 12, 2012 at 10:09 AM

This will be a frontend editor aimed at simple authenticated users employing some custom logic what needs an own editor in a custom controller. I'm trying to save a new content item :-). The content type of the item has fields and AutoroutePart attached.

I don't know why Contents/AdminController works by just just calling Create() and UpdateEditor()...