Feb 2, 2012 at 9:00 PM
Edited Feb 2, 2012 at 9:05 PM
It's for my Facebook Suite module: there are widgets that provide FB social plugins. I'd like to attach these widgets to content types, so e.g. all Pages have FB comments. Doing this with the same part the widgets have has the drawback that the widget settings
have to be configured with every content item. Therefore I'd like to configure attached widgets on a per content type basis, with TypePartEditors.
Now the easiest way would be to duplicate widget editors, widget parts, etc. as type part settings, but that's a ridiculously bloated copy-pasta. The idea I had was to basically attach widgets to content types, as following:
public class FacebookCommentsBoxSettingsHooks : ContentDefinitionEditorEventsBase
public override IEnumerable<TemplateViewModel> TypePartEditor(ContentTypePartDefinition definition)
var model = new FacebookCommentsBoxTypePartSettings();
model.WidgetEditor = _contentManager.BuildEditor(widgetItem);
yield return DefinitionTemplate(model);
Then display model.WidgetEditor in the definition template and update the widget content item in TypePartEditorUpdate() with ContentManager.UpdateEditor(). Now this would work except that since the "FacebookCommentsBoxTypePartSettings" prefix is added to
the form fields, the widget's fields (which have their own prefix assigned in the parts' driver) are not updated correctly. What could be done?
- Return another TemplateViewModel from the TypePartEditor method that only displays the widget's editor shape, without a prefix. That would work but I think the prefix should stay since it makes the fields truly unique. A better solution would be to configure
the updater to use the TypePartEditor's prefix too (but I don't think that's possible).
- Manually update the widget's interesting part (that stores the social plugin's data) in TypePartEditorUpdate() using the TypePartEditor's and the part's prefix too. This works but sound a bit hackish.
- Wait for Orchard 1.5 where AFAIK something is planned for widgets and content items (but it's a question whether widgets could be attached to content items or content types; in this case widgets should be attached to content types).
Or something else... Thank you for reading and for any help in advance.