Here's what I want to do: set the template for a new resource based on the parent resource. Not necessarily the template that is *used* by the parent resource (not a simple 'inherit template' concept), but a template that may optionally be specified by the parent template. For example, I want all children of the resource "Meetings" to use the Meetings template (even though the Meetings resource itself does not).
I know that Form Customization sets allow me to do this with constraints. I can explicitly create an FC set that sets the template to "Meetings" when the parent resource is "Meetings".
The problem is, I don't want to have to explicitly set up a new FC set each time this situation arises. Way too much administrative overhead, man.
What I'd like to do is have a TV called "childTemplate" attached to my templates, so that a user can specify that all children of the current resource should use template X.
So my thought was to write a Plugin that would do the following:
- fire either on 'OnDocFormPreRender' or 'OnDocFormRender' (I'm not sure which is appropriate)
- (for "new" resources only) determine the parent resource, and check to see whether a childTemplate was specified there
- if a childTemplate was specified in the parent, set that as the template for the new resource.
The first problem I ran into is that $resource is null for new resources when the 'OnDocFormPrerender' and 'OnDocFormRender' events fire.
(Shaun says this is not the case as of Revo 2.2, which would change things considerably).
I was able to figure out the parent by using $_GET['parent'] instead of $resource->get('parent').
However, I am not able to use $resource->set('template', $tpl), because, again, the resource is null.
So that's where I'm at with my original question, which is "how would I write a plugin to set the template for a new resource?"
However, after thinking all of this through a bit more, I'm wondering if a different approach would be better. Perhaps instead of writing the plugin described above, I should instead write one that
- fires on 'OnDocFormSave',
- sees if "childTemplate" was modified (so we're talking about a user editing the parent resource here)
- dynamically creates an FC set if necessary
In other words, specifying a template in "childTemplate" would dynamically create an FC set with the appropriate parent constraint.
Is that an insane and convoluted thought? Is it even doable?