Author Topic: civix generate:form ?  (Read 934 times)

Offline Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1001
  • Karma: 42
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
civix generate:form ?
« on: April 09, 2013, 06:13:20 am »
Hey there,

I was expecting to find a civix generate:form command  that compliments the generate:page etc. commands but coudn't find it.

Made me wonder if this is something that just isn't implemented yet or maybe there is a good reason for not implementing it / I should be looking somewhere else / for an alternative approach.

Thanks,
Michael
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Offline totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 413
  • Karma: 30
Re: civix generate:form ?
« Reply #1 on: April 09, 2013, 10:42:05 am »
It's not implemented in civix because this part of Civi's platform hasn't been documented well -- and I want to encourage new devs to down an uncharted path.

I've tried to fill in some gaps here by adding a wiki page. The page could use info on some more topics (e.g. how buttons work; when/whether/how to use Controller+StateMachine classes in conjunction with Form; and how to combine CRM_Core_Page_Basic with forms).
http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference

If we wanted, then I could produce a "generate:form" command and disclaim it as "alpha" or some-such -- and we could incrementally build up the wiki reference as adventurous people play around with it.

My general advice has been to make a simple page and then use JavaScript+CRM.api() to implement form functionality. That sidesteps documentation issues in CiviCRM-QuickForm, makes it easier to produce a rich UI, and should be more portable/maintainable in the event that Civi core switches away from QuickForm. But it may come at the disadvantage of producing forms that look/feel a bit different from Civi core.

Offline Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15784
  • Karma: 464
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: civix generate:form ?
« Reply #2 on: April 09, 2013, 02:11:27 pm »

And we do know that civi will switch from QuickForm in the next release or three :)

lobo

Online xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4285
  • Karma: 155
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: civix generate:form ?
« Reply #3 on: April 10, 2013, 01:02:22 am »
Got the bottle ready in the fridge. Hopefully, it will get better with the age ;)

Tim, do you think backbone could be used to help build the form with crmapi (eg. using getfields + backbone to build the form)?

Trying to find a pretext to explore backbone a bit more...

X+

Offline Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1001
  • Karma: 42
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: civix generate:form ?
« Reply #4 on: April 10, 2013, 05:36:13 am »
i am sure it will be an awesome party.

Quote
this part of Civi's platform hasn't been documented well

unless i am missing a few helper functions, i don't think it is 'implemented' very consistently either, perhaps because we don't haven't got functions that provide the right level of abstraction.  i always think that i am reinventing wheels when doing things like manually defining forms based on tables and then manually writing smarty templates based on these forms.

in general i am suprised at how little gets done automatically and wondering if anyone disagrees that we would benefit from having some helper methods, etc. that catered for the obvious use case.

Quote
My general advice has been to make a simple page and then use JavaScript+CRM.api() to implement form functionality. That sidesteps documentation issues in CiviCRM-QuickForm, makes it easier to produce a rich UI, and should be more portable/maintainable in the event that Civi core switches away from QuickForm.

that sounds interesting.  Do you have an example?


Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Offline totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 413
  • Karma: 30
Re: civix generate:form ?
« Reply #5 on: April 10, 2013, 08:03:05 pm »
My general advice has been to make a simple page and then use JavaScript+CRM.api() to implement form functionality. That sidesteps documentation issues in CiviCRM-QuickForm, makes it easier to produce a rich UI, and should be more portable/maintainable in the event that Civi core switches away from QuickForm. But it may come at the disadvantage of producing forms that look/feel a bit different from Civi core.

Tim, do you think backbone could be used to help build the form with crmapi (eg. using getfields + backbone to build the form)?

that sounds interesting.  Do you have an example?

The new profile designer takes this approach -- i.e. it was originally written as an extension using CRM_Core_Page, Backbone, Backbone-forms, and CRM.api. Here's a basic form for editing properties of a UFField entity:

https://github.com/totten/civicrm-core/blob/master/js/model/crm.uf.js#L95
https://github.com/totten/civicrm-core/blob/master/js/view/crm.designer.js#L656

(See also: https://github.com/powmedia/backbone-forms )

The profile designer might not be a good reference point for other developers because it has some extra requirements that make it more complex -- i.e. it runs inside a popup, and it needs to build up multiple entities (UFGroup and UFFields), and all the entities need to save atomically.

We could design an easier example for other use-cases (e.g. for cases where the field can be saved ASAP or when each entity has its own "Save" button). Some integration with getfields or similar would be handy.

Offline totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 413
  • Karma: 30
Re: civix generate:form ?
« Reply #6 on: May 04, 2013, 06:38:54 pm »
After talking with some folks at the sprint, there seemed to be a lot of support for providing a "generate:form" command (even though QuickForm isn't well documented). I've added it to the latest civix. Feel free to provide new code snippets or comments to include the templates.

https://github.com/totten/civix/commit/62289f62933352b7e3b7368c0f81006c6287f2be