Reusing a edit/create form
As a web developer, you have to deal with web forms. Why would you make a new form, and an edit form, which is basically the same.
How to handle this would be to use this design pattern:
1.) load the get item to load, if it exists. Lets call it $dataObject
2.) if $dataObject is empty/does not exist, start a new dataObject. Lets call it $dataObject
3.) dataObject is now instantiated.
4.) Do what needs to be done — for example “title” of the page, being “editing XXX”, or “new dataObject”. Whatever frontend reflections need to happen, based on if it’s new object or editing an old object.
5.) populate the form, accordingly. If the object is blank, it’ll just be populated with the default values.
6.) onSubmit()… check to see if an ID value was submitted, and the appropriate security checks, and deal accordingly. If there was no ID value, start a new dataObject, to be populated with the data submitted.
7.) $dataObject->save();
The above described is how symfony admin generator handles form reuse. While the admin generator is useful for most cases, sometimes you need to just do “more” customizations, than using the generator.
For example, you need to handle a collection of both NEW and Prior saved objects… to do batch edits, it’s easier to do it manually, instead of using the symfony-admin-generator.