CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • civix generate:form ?
Pages: [1]

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

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
civix generate:form ?
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

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: civix generate:form ?
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.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • 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 ?
April 09, 2013, 02:11:27 pm

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

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: civix generate:form ?
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+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
Re: civix generate:form ?
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

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: civix generate:form ?
April 10, 2013, 08:03:05 pm
Quote from: totten on April 09, 2013, 10:42:05 am
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.

Quote from: xavier on April 10, 2013, 01:02:22 am
Tim, do you think backbone could be used to help build the form with crmapi (eg. using getfields + backbone to build the form)?

Quote from: Michael McAndrew on April 10, 2013, 05:36:13 am
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.

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: civix generate:form ?
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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Discussion »
  • Extensions (Moderators: mathieu, totten, kasiawaka) »
  • civix generate:form ?

This forum was archived on 2017-11-26.