dhruba Posted September 15, 2013 Share Posted September 15, 2013 Hi I want to develop a new field type to store more complex but lightweight data as json. I could do that using text field but I m loosing the cool way (means object oriented way like $object->property1->property2->property3 ) to add and edit those fields. So I want a new field type to do that and it should support the admin also. How to write a module for that I need a help THANKS. Link to comment Share on other sites More sharing options...
kongondo Posted September 15, 2013 Share Posted September 15, 2013 You might want to start by reading these... http://www.flamingruby.com/blog/anatomy-of-fields-in-processwire/ http://wiki.processwire.com/index.php/Module_Creation http://processwire.com/talk/topic/4420-page-list-migrator/ - not directly related, but gives you some ideas about working with json in PW http://processwire.com/talk/topic/2394-how-to-present-your-module/ http://processwire.com/api/modules/ https://github.com/ryancramerdesign/ProcessHello https://github.com/ryancramerdesign/ProcessWire/blob/master/site-default/modules/Helloworld.module http://processwire.com/talk/topic/4410-storing-lists-in-pw-fields/ - not directly related; storing serialized field data in db... I'm not sure what you mean by "it should support the admin also". If you mean you want a GUI for it in the admin, then you are looking at a Process Module, most likely. I suggest to have a look at some of the code of the available modules as well. As for JSON, you can either use PW's wireEncodeJSON method or PHP's native json_encode. The difference between the two is that PW's removes empty vaues. 3 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted September 15, 2013 Share Posted September 15, 2013 If I create a search engine in the future, I will call it Kongondo. (Kongondo, even better then Google.) 8 Link to comment Share on other sites More sharing options...
diogo Posted September 15, 2013 Share Posted September 15, 2013 12 1 Link to comment Share on other sites More sharing options...
ryan Posted September 15, 2013 Share Posted September 15, 2013 Good links from Kongondo there. I also want to mention that if you like to learn by example, have a look at Adrian's FieldtypePhone and/or FieldtypeMapMarker modules in the modules directory (among others). These are Fieldtype and Inputfield combinations that present objects as their value, similar to what you are talking about. The big difference in your case is that your need is simpler (though not as DB friendly), because you'll be bundling it all up into a single JSON string. The place where you would convert your object into a JSON string is in your Fieldtype's sleepValue() method, and the place where you'd convert it from a JSON string to an object is in your Fieldtype's wakeupValue() method. 1 Link to comment Share on other sites More sharing options...
dhruba Posted September 15, 2013 Author Share Posted September 15, 2013 Thanks kongondo and ryan I will go through all this. 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