This addition generates a pattern template for a form with comments for the potential field values. Its just a jumpstart on a [form] pattern.

Comments

ChrisBryant’s picture

This looks like a wonderful patch and I'm looking forward to testing it soon... Thanks!

johnbarclay’s picture

I already found a bug. Here's the file. I think this can be committed anytime after some testing.

johnbarclay’s picture

StatusFileSize
new5.51 KB
apotek’s picture

Thanks for the bug alert. I reversed the patch (I think), given that patch seems to have a bug/feature in this regard:

 $ patch <patterns_form_helper.patch 
(Stripping trailing CRs from patch.)
patching file patterns.module
Reversed (or previously applied) patch detected!  Assume -R? [n] y
(Stripping trailing CRs from patch.)
patching file form_helper.inc

Then I applied the new patch

$  wget http://drupal.org/files/issues/patterns_form_helper2.patch
2010-05-05 13:33:12 (67.5 KB/s) - `patterns_form_helper2.patch' saved [5644/5644]
$ patch <patterns_form_helper2.patch 
(Stripping trailing CRs from patch.)
patching file patterns.module
(Stripping trailing CRs from patch.)
patching file form_helper.inc
$ drush pm-update

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.

johnbarclay’s picture

and 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.

johnbarclay’s picture

I 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:

info:
  title: 
  description: 
  author: 
  category: 
  author_email: 

modules:


actions:
  -tag: form
     form_id: user_admin_settings

#Public registrations:
# options: 0 ( Only site administrators can create new user accounts. ), 1 ( Visitors can create accounts and no administrator approval is required. ), 2 ( Visitors can create accounts but administrator approval is required. ), 

      user_register: 2

#Require e-mail verification when a visitor creates an account:

      user_email_verification: 1

#User registration guidelines:

      user_registration_help: 

#Welcome, new user created by administrator:

      admin_created: 

#Welcome, no approval required:

      no_approval_required: 

#Welcome, awaiting administrator approval:

      pending_approval: 

#Password recovery email:

      password_reset: 

#Account activation email:

      activated: 

#Account blocked email:

      blocked: 

#Account deleted email:

      deleted: 

#Signature support:
# options: 0 ( Disabled ), 1 ( Enabled ), 

      user_signatures: 0

#Picture support:
# options: 0 ( Disabled ), 1 ( Enabled ), 

      user_pictures: false


      settings: 

#Prefix for "Username" field on login page:

      itweak_login_username_inpage_prefix: |
  <p>Logging onto the COE Apps site can be done with one of two types of accounts:</p>
  <ul>
  <li>Active Directory (AD) Accounts Current UIUC faculty, staff, and students should always use their AD account to logon. Their user name will be their UIUC Netid. See http://accounts.ad.uiuc.edu/.</li>
  <li>College of Education App Accounts. "External users" that do not have a UIUC NetID should  <strong><a href="/user/register">Create a new COE Apps account</a></strong>.</li>
  
  </ul>
  

#Label for "Username" field:

      itweak_login_username_label: >
  Enter your UIUC Netid or COE Apps
  Account Username

#Label for "Password" field:

      itweak_login_password_label: >
  Enter your Active Directory Password or
  COE Apps Password

#Show "Register" button on user login:

      itweak_login_register_button: 0

#Name for "Register" button:

      itweak_login_register_button_name: 

#Name for "Log in" button:

      itweak_login_login_button_name: 

#Text for "Create new account" link:

      itweak_login_register_name: 

#Text for "Request new password" link:

      itweak_login_recover_name: 

#URL for "Request new password" link:

      itweak_login_recover_url: 

XML of user settings form from form helper:

<?xml version="1.0" encoding="ISO-8859-1"?>
<pattern>
  <info>
    <title></title>
    <description></description>
    <author></author>
    <author_email></author_email>
    <version></version>
    <category></category>
    <core>6.x</core>    
  </info>
 
  <actions>

<form>
<form_id>user_admin_settings</form_id>

<!--Public registrations:
 options: 0 ( Only site administrators can create new user accounts. ), 1 ( Visitors can create accounts and no administrator approval is required. ), 2 ( Visitors can create accounts but administrator approval is required. ), -->
<user_register>2</user_register>


<!--Require e-mail verification when a visitor creates an account:-->
<user_email_verification>1</user_email_verification>


<!--User registration guidelines:-->
<user_registration_help></user_registration_help>


<!--Welcome, new user created by administrator:-->
<admin_created></admin_created>


<!--Welcome, no approval required:-->
<no_approval_required></no_approval_required>


<!--Welcome, awaiting administrator approval:-->
<pending_approval></pending_approval>


<!--Password recovery email:-->
<password_reset></password_reset>


<!--Account activation email:-->
<activated></activated>


<!--Account blocked email:-->
<blocked></blocked>


<!--Account deleted email:-->
<deleted></deleted>


<!--Signature support:
 options: 0 ( Disabled ), 1 ( Enabled ), -->
<user_signatures>0</user_signatures>


<!--Picture support:
 options: 0 ( Disabled ), 1 ( Enabled ), -->
<user_pictures></user_pictures>

-->
<settings></settings>


<!--Prefix for "Username" field on login page:-->
<itweak_login_username_inpage_prefix>
<![CDATA[<p>Logging onto the COE Apps site can be done with one of two types of accounts:</p>
<ul>
    <li>Active Directory (AD) Accounts Current UIUC faculty, staff, and students should always use their AD account to logon. Their user name will be their UIUC Netid. See http://accounts.ad.uiuc.edu/.</li>
    <li>College of Education App Accounts. "External users" that do not have a UIUC NetID should  <strong><a href="/user/register">Create a new COE Apps account</a></strong>.</li>

</ul>

]]></itweak_login_username_inpage_prefix>


<!--Label for "Username" field:-->
<itweak_login_username_label>Enter your UIUC Netid or COE Apps Account Username</itweak_login_username_label>


<!--Label for "Password" field:-->
<itweak_login_password_label>Enter your Active Directory Password or COE Apps Password</itweak_login_password_label>


<!--Show "Register" button on user login:-->
<itweak_login_register_button>0</itweak_login_register_button>


<!--Name for "Register" button:-->
<itweak_login_register_button_name></itweak_login_register_button_name>


<!--Name for "Log in" button:-->
<itweak_login_login_button_name></itweak_login_login_button_name>


<!--Text for "Create new account" link:-->
<itweak_login_register_name></itweak_login_register_name>


<!--Text for "Request new password" link:-->
<itweak_login_recover_name></itweak_login_recover_name>


<!--URL for "Request new password" link:-->
<itweak_login_recover_url></itweak_login_recover_url>

</form>
  </actions>
</pattern>
apotek’s picture

Noticing 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

vaish’s picture

First 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

vaish’s picture

Status: Needs review » Needs work
ChrisBryant’s picture

I'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!