Author: ly.meng.work
Description:
Patched SF_FormPrinter, based on 2.2
This enhancement is a continuation of this upgrade:
And is thus a solution to the following situation, when one want to have fields in a template that are themselves populated by a list of templates, and want to be able to edit that using "nested multiple forms".
The logic is to have in the main form a hidden field with a "placeholder" attribute. Then, a multiple-instance form is defined outside of the main form, as usual, but also has a "placeholder" attribute set at the same value as the hidden field (let's say we talk about the Mayors parameter).
When the page is edited with the form, the list of templates set in the Mayors parameter are taken out of the Town template, and appended at the end of the data, as if we were in a normal multiple-instance form situation. A hidden field is inserted in the HTML at the mayors position, set with a special "@replace_mayors@" value, and a "@insertpoint_mayors@" text is also inserted. Then all the HTML continues to be generated. Upon coming on the Mayors templates, these parts are processed by the separate multiple-instance form defined for this kind of templates, but are not appended to the end of the current HTML as usual. All the HTML corresponding to these templates is reinserted at the @insertpoint_mayors@ position, which finally gives the illusion to have a multiple-instance nested form inside the main form once everything is displayed.
On form submission, the fields values are translated into medaiwiki templates as usual, and the Mayors parameter is first set to "@replace_mayors@" (the hidden field value), but then the list of templates generated from the multiple-instance form is reinserted in this position.
I set up a test instance here to see show it works: http://www.saintseiyapedia.com/wikitest/Main_Page
user/pass: test/testsmf
Issues:
1.it is only possible to to 1 depth level of nested templates (but possible to get as many nested templates on the base depth as you want). Putting a placeholder system in something that is already a placeholder won't work. To do that, a lot of refactoring into a recursive solution would be needed. I tried to not touch the overall logic.
Notes:
- Normal multi-instance forms still work and can even be used at the same time as placeholder ones. By the way, since this fix tries to not alter too much the original logic, some code duplication was done at the end of the multi-instance temaplte part, but a better refactoring woul be to remove the normal multi-instance logic, and use the placeholder logic instead, since the original functionality could be easily mimicked by putting a dummy placeholder value at the end of the currently processed HTML.
- Most explanations are in the code comments, usually delimited by addition and remove tags
Version: unspecified
Severity: enhancement
attachment SF_FormPrinter.php ignored as obsolete