I have a form for an object called AccountImport. This form lives in an admin-generated module. In addition to the fields that map directly to this object’s attributes, I need a couple extra fields.
If I just add the fields to the AccountImport form, it won’t save correctly because the form will no longer match the AccountImport object.
If I create a template manually and splice the extra fields in that way, I’m throwing away all the stuff the admin generator gives me for free (i.e. formatting, “Back to list” button, save buttons).
What’s a “good” way to do what I’m trying to do?
If you define additional fields in
generator.yml, you can override one of the admin generator actions to handle the fields however you want.Look at the generated actions.class.php in cache/YOURAPP/YOURENV/modules/autoYOURMODULE/actions/actions.class.php . You can override any of those functions with your own in apps/YOURAPP/modules/YOURMODULE/actions/actions.class.php, because it inherits from that cached file. When you make changes to generator.conf, the cached file is updated but your code will still override it. You probably want to override
processForm().I have an example of this in step 5 at this blog post:
When I realized I could read the generated files in the cache to see exactly what the admin generator was doing, and that I could override any part of them, it made me a lot more productive with the admin generator.