-
☆ A M B ☆
- 24,524 Posts
I was wondering about that. I've tried to use form customization for other things, but the filter was on resource ID, and that didn't work out too well. Of course, until a resource is actually written to the database it can't have an ID...
Odd...when assigning a template in the modx-resource-main-right section, for example putting 2 (for template #2), the label of the Template select drop-down is changed to what I put, but the item in the select field itself does not change, and of course the resource's template is not changed from the default.
Well, pooh! I was filling out the wrong field in the grid! It works fine when I put the 2 in the right field. Duh.
[ed. note: sottwell last edited this post 12 years, 5 months ago.]
FYI, $this is almost never used in plugins, instead, MODX generally sends the object itself, which is available in the plugin as something like:
$resource
$user
$chunk
$snippet
etc.
I think one reason your plugin didn't work is that (AFAIK) there is no event called 'OnBeforeDocFormRender'
I think you wanted 'OnDocFormPrerender'.
There's a comprehensive list here:
http://bobsguides.com/modx-revolution-events.html
The plugin would be quite a bit faster than using Form Customization (and possibly more reliable), though when it comes to saving resources, the time difference probably doesn't matter.
-
☆ A M B ☆
- 24,524 Posts
$properties. Try using it as an object get "Call to a member function get() on a non-object" error. Try using it as an array, nothing happens.
http://bobsguides.com/modx-revolution-events.html#OnDocFormPrerender-5368643de53c8
I think that's an artifact based on how it's called in the resource class file. I suspect that $id and $mode would always be the variables available.
-
☆ A M B ☆
- 24,524 Posts
Well, after running some tests, it's definitely not there for a plugin using that event. I haven't been able to find any way to influence any of the default field settings using OnDocFormPrerender. And I have to wonder how, before the form for creating the new resource, it can provide an ID? That won't be available until the resource is actually saved to the database.
The ID would only be available for updating an existing object. The mode should be available either way (in fact the $mode member is set by checking whether there's an id or not).
ClassExtender uses OnDocFormPrerender to modify the form. MODX uses the return value from the plugin, but I'm not sure what method (if any) would modify the default settings. The return value from the plugin just gets appended to the form.
CacheMaster does modify the "Clear Cache" checkbox, so you might look at its code.