Jump to content

Searching for a fieldtype / inputfield example module


pwFoo
 Share

Recommended Posts

Fieldtypes are not for the faint-hearted ; but don't let that discourage you! They will seem difficult in the first instance, but once you get to know what does what (some of the generic methods), you will absolutely love Fieldtypes and appreciate the thoughtfulness that Ryan put into designing PW. I used to be a sucker for Process Modules but now am totally hooked on Fieldtypes. I dare say they are the heart of ProcessWire. 

Here's some important homework from the forums that will help you with the generic methods I mentioned above. The most important thing to remember is that with Fieldtypes, you are just a heartbeat away from the database so sanitizing data and retrieving data in some expected format is crucial. Enjoy!

https://processwire.com/talk/topic/671-relationship-between-sleepvalue-wakeupvalue-and-sanitizevalue-methods/

https://processwire.com/talk/topic/4105-module-create-a-pages-findquery-as-a-field/?p=40411

https://processwire.com/talk/topic/1936-remove-entry-from-pagesfield-via-api/

And don't forget this classic: http://www.flamingruby.com/blog/anatomy-of-fields-in-processwire/

Edit:

  1. One more tip. Working with Fieldtypes, you will want to have a tab open showing the table (database) of the field you are working on so that you can observe how things get saved (or don't get saved!).
  2. The FieldtypeEvents that @adrian pointed too uses some advanced techniques (e.g. moving some methods to their own PHP classes); you don't always have to do that. It really depends on your coding style.
  3. I'd also suggest you have a look at RuntimeMarkup or Concat Fieldtypes and check out the comments. These Fieldtypes don't save anything to the db but have some useful comments.

Edit 2: A diagram RE Fieldtypes database schema

https://processwire.com/talk/topic/5040-events-fieldtype-inputfield-how-to-make-a-table-fieldtypeinputfield/?p=85759

Edited by kongondo
Added extra info...
  • Like 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...