Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This addition generates a pattern template for a form with comments for the potential field values. Its just a jumpstart on a [form] pattern.
Comment | File | Size | Author |
---|---|---|---|
#3 | patterns_form_helper2.patch | 5.51 KB | johnbarclay |
patterns_form_helper.patch | 5.37 KB | johnbarclay |
Comments
Comment #1
ChrisBryant CreditAttribution: ChrisBryant commentedThis looks like a wonderful patch and I'm looking forward to testing it soon... Thanks!
Comment #2
johnbarclay CreditAttribution: johnbarclay commentedI already found a bug. Here's the file. I think this can be committed anytime after some testing.
Comment #3
johnbarclay CreditAttribution: johnbarclay commentedComment #4
apotek CreditAttribution: apotek commentedThanks for the bug alert. I reversed the patch (I think), given that patch seems to have a bug/feature in this regard:
Then I applied the new patch
The patch basically pre-pended the entire file into the top of my former file. Did not apply cleanly.
I hand-edited the file afterwards, and I have to say "wow!" this will make things a TON easier. thanks.
Just thought I'd add this in case anyone else wanted to be saved some search-engine-ing.
Comment #5
johnbarclay CreditAttribution: johnbarclay commentedand another bug I'm working on. It did not deal with valid xhtml, which also needs to be embedded in CDATA tags. It would put bad xml in CDATA, but not good xml.
On the good news side, I used this to export a user settings form successfully. This one is always a customization.
Comment #6
johnbarclay CreditAttribution: johnbarclay commentedI think I've got this working well. Below is an xml and yaml example of the user settings form. I know I can't import yaml and the filesystem isn't discovering the file. If this looks about right, let me know and I'll post the patch. With the form helper, there is no need to accomodate multidimensional arrays since they aren't present. But after a little work with YAML I can see it will be easy to implement in the other "generate" functions.
YAML of user setting form from form helper:
XML of user settings form from form helper:
Comment #7
apotek CreditAttribution: apotek commentedNoticing this in my error log when I list modules at admin/build/modules/list:
PHP Fatal error: Cannot unset string offsets in /path/path/path/docroot/sites/all/modules/patterns/form_helper.inc on line 15
Comment #8
vaish CreditAttribution: vaish commentedFirst of all, I have to say this is amazingly important patch. Thanks for working on it.
I did a quick review and would like to point to few things:
1. I also came across the bug reported in comment #7
2. I would love to split code of patterns module into more inc files sooner or later so I would suggest that you put form_helper.inc in includes subfolder (needs to be created) and we will follow that convention in the future with other inc files.
3. re comment #6: please always post your latest patches. If it was already posted I could have review it today.
4. re YAML support: I'm not sure how did you generate YAML pattern but I can immediately see why it's not recognized. spyc library that we use for handling YAML is unfortunately not tolerating empty lines nor comments between actions. See YAML files bundled with the patterns for working syntax. My approach to generating YAML would be to prepare PHP array and let spyc generate valid YAML for me.
5. As far as I can see, currently your code generates form actions even for the modules supported by patterns. I'm still considering if that's good approach or not. Any thoughts on that?
6. I tested the helper on "add imagecache action" form and didn't get expected results. Data related to the action was not missing.
7. I would suggest using <pre> tag instead of textarea for printing the generated pattern code.
Good work and please keep posting new patches :)
Thanks
Comment #9
vaish CreditAttribution: vaish commentedComment #10
ChrisBryant CreditAttribution: ChrisBryant commentedI've been using this and it's great! It would be nice to have it optionally output YAML files as well if possible. :-)
Thanks for sharing it!