This project is read-only.

Wrap contentitem with contentpart?

Topics: Writing modules
Jun 15, 2011 at 10:40 AM

Is it possible somehow to wrap the entire content of a Content type from within a content part? Specifically, I want a Content part that wraps the entire content in a <form>. Actually, just wrapping the existing Fields in a form would work just as well.

Jun 15, 2011 at 11:00 AM

It wouldn't be recommended, because other parts might add their own forms, and you start getting POST errors when that happens (i.e. it's already happened to me, specifically with the Stars module).

What exactly are you trying to achieve - I guess you have a number of fields that you want to post from the front end? You should probably create your own part and build the whole UI you need.

Jun 15, 2011 at 11:51 AM

Yes, exactly. I'm creating a site for a customer that wants to build custom mail forms. Ie, add a bunch of fields and those will be posted in a simple manner via email. So preferrably I would want to reuse existing structure to add fields, instead of adding yet another field-adding logic within the Content part.

So I do see your point, but this will be used very controlled and site-specific.

Jun 15, 2011 at 3:28 PM

There was a discussion before about this type of feature. As far as I know, nobody's built anything yet, but it'd be a pretty good module.

There are actually three ways you could approach it;

- What I suggested before which is to add the fields to the part itself; then from the part itself hook into a field rendering process to display the form. Could be really tricky tho.

- Use a ShapeTableProvider to handle Content shapes, and you can add a Wrapper template at that stage by investigating shape.ContentItem to see if it had your part, and checking other properties like DisplayType=="Detail" etc. You could make this work but I reckon it'd be a bit flimsy and not the most flexible way.

- Most complex-sounding but probably best option; display a complete editor for the content type. This means the user can add *any* parts or fields and have them participate in the contact form; and when they'd finished, you would have their full contact form entries in your database as a content item (which of course you'd want to keep private). You'd have to copy the Create and CreatePOST actions from AdminController in Core.Contents to have the editor appear in the front-end, and then add in your own logic for sending an email when it's done. You wouldn't actually need to put all the inputted details into the email, because it could have a link to view the full contact details on the site. Thinking about it this might actually be easier to get working properly than the other two options!