benbyf Posted July 19, 2016 Share Posted July 19, 2016 Finding it quite fustrating work with fields from a module, I cant seem to find any good docs or forum threads. For example I'm making a new field on install of my module, but ideally I would like to know how to set flags, default value, max- min etc for that field but it's not obvious to me. All I can mange so far. $f = new Field(); // get a field type $f->type = $this->modules->get("FieldtypeInteger"); $f->name = $this->fieldName; $f->label = 'Publish Page later'; $f->save(); // save the field I'm finding this elsewhere with integrating with the admin, but not at all with the API itself which has great documentation. Any advice, guidance would be great! 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 19, 2016 Share Posted July 19, 2016 The easiest way to find those properties is to enable debug mode and hovering over the "collapse" icon of those options, when editing the field. This will often show you how those properties are named. Also the php docblocks of those modules are geting better and better in stateing those as well. Use them just like that: $this->min = 1. 2 Link to comment Share on other sites More sharing options...
horst Posted July 19, 2016 Share Posted July 19, 2016 @benbyf: I have used to look into the fields exporter to find out some things and found it very quick and nice method. I created a few fields with all settings I'm interested in, select it in the exporter and looked to the json data: Spoiler { "pdf": { "id": 189, "type": "FieldtypeFile", "flags": 0, "name": "pdf", "label": "PDF-Dokument", "extensions": "pdf", "maxFiles": 1, "outputFormat": 2, "defaultValuePage": 0, "inputfieldClass": "InputfieldFile", "descriptionRows": 2, "icon": "file-pdf-o", "fileSchema": 2, "collapsed": 0, "tags": "bilder-dateien", "overwrite": null, "outputString": "", "textformatters": "", "entityEncode": "", "useTags": "", "showIf": "", "columnWidth": 100, "required": "", "requiredIf": "", "unzip": "", "noLang": "" } } So, this alone is not enough, but after seeing a compact list of possible properties I can pickup one of interest and run a search for that in the inputfield class in my editor. <kidding>Don't wail about uncomplete docs or missing tuts. Instead search, find and learn, - we are waiting for you to contribute new tuts!</kidding> 4 Link to comment Share on other sites More sharing options...
kongondo Posted July 19, 2016 Share Posted July 19, 2016 Unfortunately there's not enough docs at the moment. Isn't that why you are writing docs? . Joking aside... 3 Tips Due to the paucity in documentation most (all?) of us learned by looking at other modules. Simpler core modules, custom modules such as Batcher, Trashman, etc. The module Blog creates fields on the fly during installation. Have a look at the code here. Also have a look at ProcessBlog phpMyAdmin: have a look at the table fields. You will see a list of all the installed fields. Look at the column 'data'. All field settings are stored in there as JSON as key=>value pairs. Why is this important you ask? All (?) the keys in the strings correspond to the field properties that can be set...e.g. $field->description, $field->derefAsPage, etc. Also have a look at the column 'label'. The trick here is to open a field for editing and add and remove settings and save while keeping an eye of the field's 'data' column to observe changes. In respect of templates, same trick can be used on the table 'templates' http://kongondo.github.io/ProcessWireAPIGen/dev/class-Field.html 3 Link to comment Share on other sites More sharing options...
benbyf Posted July 19, 2016 Author Share Posted July 19, 2016 29 minutes ago, horst said: @benbyf: I have used to look into the fields exporter to find out some things and found it very quick and nice method. I created a few fields with all settings I'm interested in, select it in the exporter and looked to the json data: This is genius, thanks @horst. Also thanks for all the tuts jokes... I never thought of myself as a backend guy so hope they're up to scratch and I always comments. @kongondo this is great http://kongondo.github.io/ProcessWireAPIGen/dev/class-Field.html thanks. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now