Jump to content

Fieldtype Modules?


BrendonKoz
 Share

Recommended Posts

Hi all, hopefully this is the correct (sub)forum to ask.

I'm trying to undertake my first real (worthy?) module. I understand Textformatters, Markup, and Process modules, but I'm now looking to, I believe, create a module that behaves similarly to the Map Marker module(s); in my case I'm looking to add book information from an external service (insert ISBN or title into a text field and the service returns data that can then fill in other various fields).

I'm confused for a few reasons...it seems I was not the only one.

1. Inputfield vs Fieldtype:
I compared Ryan's FieldtypeMapMarker module and noticed that it also contained an Inputfield module. From the documentation's description between Fieldtypes and Inputfields I had a hard time discerning where my particular module would be categorized -- is this because I would also need two modules? Fieldtype: "Fieldtypes are modules that define a data type and field used to hold content for pages", and Inputfield: " One to gather input, and the other that handles the additional data (ex: author, publication date, cover art URL, etc.), that would otherwise be non-core?

2. For examples, I was trying to compare a few different FieldType modules, I looked at FieldtypeMapMarker by Ryan, FieldtypeDimension by soma, and InputfieldFlickr by apeisa (not a Fieldtype, but does something similar to MapMarker). They each seem to handle things differently (or perhaps I was looking too closely at comparing Flickr to MapMarker). When comparing any of these to the newer markup for module code I think I was just looking at too much all at once, but...are there actually multiple ways to go about doing the same thing that is fully supported by the CMF?

3. In what instances would a Fieldtype not also have an Inputfield (or some other form of input)? If not, is a Fieldtype simply a glue module?

I'm also trying to determine if there are any other specific methods that are used/required solely for Fieldtypes by ProcessWire...

Hopefully someone can help me clarify all of this. Thank you if you can!

  • Like 1
Link to comment
Share on other sites

Simply put: a field is an interface to DB, an inputfield is an interface to user. One does not necessitate the other, but for some complex data types, you may need to build a custom inputfield (like MapMarker).

If you're going to store information about multiple books on a single page, then you need to extend FieldtypeMulti class (FieldtypeEvents, FieldtypeNotifications, FieldtypeComments for example), to store information about a single book per page, you need to extend regular Fieldtype class (FieldtypeText, FieldtypeDatetime etc).

If you want to allow more than 1 property to be used in selectors, then you need to use multiple table column in DB. This means you need to override getDatabaseSchema() method and specify a more complex table structure.

Edit:

Based on your description, you expose only one input to the user for ISBN/title, filling the rest is up to you (by fetching from a web service). You have two options: either fetch the data using fieldtype or using inputfield. Using inputfield to do fetch the rest of the data sounds more appropriate, because the purpose of the fieldtype is validation, formatting, sanitization querying and saving data from/to database, i.e. it only deals with the given data. An inputfield, however, collects and prepares all data that needs to be written to the database and presents it to a fieldtype.

 

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

It seems that, when developing a Fieldtype that requires user input (Inputfield, in this case), both modules must be developed in tandem?

In other words, it's not something that could easily be tested against during development to create just the Fieldtype, or just an Inputfield (again, for something like this)?

I didn't see your Edit before, but that was very helpful, as well as the mention of extending FieldtypeMulti (instead of just Fieldtype) -- thank you!!


...just saw the Module.php file in core -- so THAT's where all of the documentation is! :D

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

2 minutes ago, BrendonKoz said:

It seems that, when developing a Fieldtype that requires user input (Inputfield, in this case), both modules must be developed in tandem?

When your requirements exceed what native modules can offer, then, yes you need to implement an Inputfield too. 

3 minutes ago, BrendonKoz said:

it's not something that could easily be tested against during development to create just the Fieldtype, or just an Inputfield (again, for something like this)?

Just use an inputfieldtextarea and show a json of your field data until you start developing your specialized Inputfield.

  • Like 1
Link to comment
Share on other sites

17 minutes ago, BrendonKoz said:

Module.php file in core -- THAT's where all of the documentation is! :D

So many goodies hidden in the core. 

Find a proper IDE that lets you navigate around classes easily (PhpStorm, free for students, yay!), and you're pretty much set.

  • Like 2
Link to comment
Share on other sites

Yes, I think I might have to. I'm using Atom right now and although there are Intellisense packages, it's already seeming sluggish. I'll give VS.code a try (also built on electron), but will likely need to buy a license to PHPStorm. Thanks again!

Link to comment
Share on other sites

17 hours ago, abdus said:

Find a proper IDE that lets you navigate around classes easily (PhpStorm, free for students, yay!), and you're pretty much set.

could you please provide some insights on how you are using it? i'm also using vscode because of a recommendation here in the forum by @fbg13 and like it so far, but i would love to see how others do :)

Link to comment
Share on other sites

but i would love to see how others do

I believe Ryan is using PHPStorm during development of ProcessWire, otherwise he wouldn't have added (and maintained) the .phpstorm.meta.php file to the GitHub repo that helps with its intellisense abilities. There's a 30-day trial of PHPStorm so if it's not better to you than VScode then you won't need to pay. :) I think PHPStorm's integrated debugger would likely work better though. (I'd still like to give VScode its fair chance, so will be testing that first.)

Link to comment
Share on other sites

@bernhard Here's a preview of some features I use frequently:

Variable hinting for API variables for intellisense (when not using API functions, such as page() instead of $page)
Ctrl + Q for instant documentation
Ctrl + Left Click for instant jump to source.
Error hinting

hint.thumb.gif.46d45dbfc1c9bc745328ad8183b3377e.gif

Refactoring and reformatting

image.thumb.gif.811626cfd4486869c2257215dd453ba2.gif

Proper step by step debugging using XDebug
Stack trace, scope and global variables, console
Variable watchers

image.thumb.gif.844f52786bdeb1359a828d175e867760.gif

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

I recently switched to VSCode from Sublime Text and I haven't looked back since. Was hoping to make a demo of how I'm using it in my development...but haven't got the time...yet. I'm getting intellisense, step-by-step debugging (including CSS debugging!), terminal, grep, diff checker, push to Github, JS/HTML/CSS/PHP documentation, phpDocs, etc...the works!

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

1 hour ago, kongondo said:

I recently switched to VSCode from Sublime Text and I haven't looked back since. Was hoping to make a demo of how I'm using it in my development...but haven't got the time...yet. I'm getting intellisense, step-by-step debugging (including CSS debugging!), terminal, grep, diff checker, push to Github, JS/HTML/CSS/PHP documentation, phpDocs, etc...the works!

Hey @kongondo - I am actually just playing around with VSCode right now and autocompletion for PW seems weird. Some of the wire functions outside of class scope show up, eg:

59de8e621d385_ScreenShot2017-10-11at2_33_38PM.png.36f201a6510da3c46baa9a5573625202.png

but that's not all of them, and nothing in any of the PW classes shows up at all. VSCode seemed to index my entire project folder, so I think it should have everything. Any tips you have discovered for this?

PS @abdus - I took a quick looks at PHPStorm, but it seemed really sluggish (even after indexing had finished) - did you do any tweaks to get it snappy enough to work with?

  • Like 1
Link to comment
Share on other sites

1 hour ago, adrian said:

but it seemed really sluggish (even after indexing had finished)

Well, for me it's much faster than VSCode. Admittedly, it starts off a bit slow but after indexing is complete (~5-6 seconds), you shouldn't have any noticeable delays. I can work on multiple projects simultaneously without any lag (on XPS 13 2016, i5 6200U, 8GB RAM, EVO 850 500GB SSD).  It performs code analysis and syntax highlighting lazily so having many files open wouldn't affect the performance that much. But having said that, you can disable language injections  or enable battery saving mode to disable most power hungry features. But many of these features are what makes PHPStorm great, so don't cripple it down to a regular editor.

https://stackoverflow.com/questions/23842924/phpstorm-7-very-slow-and-sluggish-on-netbook-optimize-ide-for-responsiveness

Also, it seems mostly mac users are experiencing this problem


 

  • Like 1
Link to comment
Share on other sites

12 hours ago, kongondo said:

I recently switched to VSCode from Sublime Text and I haven't looked back since. Was hoping to make a demo of how I'm using it in my development...but haven't got the time...yet. I'm getting intellisense, step-by-step debugging (including CSS debugging!), terminal, grep, diff checker, push to Github, JS/HTML/CSS/PHP documentation, phpDocs, etc...the works!

i also switched from sublime and overall like vscode a lot. only thing missing is a proper intellisense/code completion so i would be very interested in seeing how that works for you :) thanks!

Link to comment
Share on other sites

  • 2 weeks later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...