OLSA Posted August 10, 2018 Share Posted August 10, 2018 Hello for all, ConfigurationForm fieldtype module is one my experiment from 2016. Main target to build this module was to store multiple setup and configuration values in just 1 field and avoid to use 1 db table to store just single "number of items on page", or another db table to store "layout type" etc. Thanks to JSON formatted storage this module can help you to reduce number of PW native fields in project, save DB space, and reduce number of queries at front-end. Install and setup: Download (at the bottom ), unzip and install like any other PW module (site/modules/...). Create some filed using this type of field (ConfigurationForm Fieldtype) Go to field setup Input tab and drag some subfields to container area (demo). Set "Name" and other params for subfields Save and place field to templates ("Action tab") How to use it: In my case, I use it to store setup and configurations values, but also for contact details, small content blocks... (eg. "widgets"). Basic usage example: ConfigForm fieldtype "setup" has subfields: "limit", type select, option values: 5, 10, 15, 20 "sort", type select, option values: "-date", "date", "-sort", "sort" // get page children (items) $limit = isset($page->setup->limit) ? $page->setup->limit : 10; $sort = isset($page->setup->sort) ? $page->setup->sort : '-sort'; $items = $page->children("limit=$limit, sort=$sort"); Screenshots: Notes: Provide option to search inside subfields Provide multilanguage inputs for text and textarea field types Provide option for different field layout per-template basis Do not place/use field type "Button" or "File input" because it won't works. Please read README file for more details and examples Module use JSON format to store values. Text and textarea field types are multilanguage compatible, but please note that main target for this module was to store setup values and small content blocks and save DB space. Search part inside JSON is still a relatively new in MySQL (>=5.77) and that's on you how and for what to use this module. Thanks: Initial point for this fieldtype was jQuery plugin FormBuiled and thanks to Kevin Chappel for this plugin. In field type "link" I use javascript part from @marcostoll module and thanks to him for that part. Download: FieldtypeConfigForm.zip Edit: 14. August 2018. please delete/uninstall previously downloaded zip Regards. 19 4 Link to comment Share on other sites More sharing options...
OLSA Posted August 14, 2018 Author Share Posted August 14, 2018 Here are more details and some news about this module. What's new (14. August 2018.): - fix small bug - search by subfields - different layouts per-template basis Examples: 1) 1 single field for configuration and setup instead 7 PW native fields On "Home" administration page want to have global config options (stylesheet, development or production mode), and SEO settings fields. On category pages need to have options to change number of children in list, provide option to select different layouts, and SEO settings fields. Conclusion, need to have 7 fields: stylesheet (select), development (select or check), SEO fields (eg. title, description and robots), limit, layout. Create field "setup" with all needed subfields: But also want to have different field layout inside Home and category pages. For that we use "Compact view" inside template setup. Result, same field but with different inputs and layouts. On site are dozen of categories and want to find where are used grid and where list layout. Or, website is in still development mode and want to find NOINDEX categories, etc... 2) Multiple different textareas on "basic-page" and "basic-page-2" templates using 1 single field Task: - textarea1, textarea2 and textarea3 on basic-page template - textarea1, textarea4, textarea5 on basic-page-2 template - all that with 1 PW field Create field "content" with 5 textarea field types (textarea1...textarea5) Set Visibility condition like this: basic-page=textarea1, textarea2, textarea3 basic-page-2=textarea1, textarea4, textarea5 Inside Action tab add field to templates basic-page and basic-page-2. Later in page administration are only desired textarea inputs. Search: find all pages where textarea1 contain word "Toronto" $items = $pages->find('content.textarea1*=Toronto'); Or in admin backend using lister: In front side: $selector = 'content.textarea1*=Toronto'; $items = $pages->find($selector); if($items->count){ echo "<h2>Find items: {$items->count}</h2>"; echo "Selector:<pre>$selector</pre>"; foreach($items as $item){ echo $item->title .', template: '. $item->template->name; echo '<br />'; } } Note: this example is only for demostrations and I didn't test this in case of few thousands pages. 5 Link to comment Share on other sites More sharing options...
dragan Posted August 14, 2018 Share Posted August 14, 2018 Great work! Thanks for sharing. Unfortunately, I didn't have time yet to try this out, but I'll give it a go in the next couple of days. I can imagine quite a few real-world usage scenarios for this. 2 Link to comment Share on other sites More sharing options...
dragan Posted August 15, 2018 Share Posted August 15, 2018 Zdravo Sasa, kako je sunce u Crnoj Gori? ? I installed your module and played around a bit. Looks good so far. Only thing I spotted: the PW width settings are not being displayed as intended, when I choose "compact view". In normal view, it's working fine. And also, some elements are a bit too close to each other, when choosing compact view: (checkbox and radio labels) 1 Link to comment Share on other sites More sharing options...
OLSA Posted August 15, 2018 Author Share Posted August 15, 2018 Dragane, odlicno, samo da je malo manje vruce ;) CompactView is html table view and idea for that type of layout was to use it in cases where are inputs closely related (eg. some contact details), and inside repeaters because don't take too much space (can open few repeater items, and at the same time, view fields in all of them). I missed to write in notes that PW Width value is not used inside CompactView layout. Sorry but it's possible that I skiped to write and some other notes, and feel free to ask me anything that is not clear or confusing. Fields what I used in almost 90% are: select, text, textarea, page and link. Radio and checkboxes very, very rarely (can't remeber), and in that case I prefer to use select. Please can you try to add to the end of module css file (module directory... site/modules/FieldtypeConfigForm/assets/css/admin.css) this few lines: .CompactView .InputfieldCheckboxesStacked, .CompactView .InputfieldRadiosStacked {list-style:none;padding-left:0;} .CompactView .InputfieldCheckboxesStacked input, .CompactView .InputfieldRadiosStacked input {margin-right:10px;} , and after it refresh browser page (CTRL+F5) and check if it will be better? Thanks and regards! 3 Link to comment Share on other sites More sharing options...
dragan Posted August 15, 2018 Share Posted August 15, 2018 Yep, much better. I also removed the 12px font-size for the compact view label, it somehow looks weird to me if it's smaller than the rest, but that's just personal preference. Thanks for clarifying that the width is ignored in compact view on purpose. 1 Link to comment Share on other sites More sharing options...
dragan Posted August 18, 2018 Share Posted August 18, 2018 On 8/10/2018 at 7:34 AM, OLSA said: Notes: Provide option to search inside subfields Provide multilanguage inputs for text and textarea field types Provide option for different field layout per-template basis Do not place/use field type "Button" or "File input" because it won't works. Please read README file for more details and examples May I suggest to simply exclude button and file inputs - it's kinda pointless to see them there as available input fields, when in fact they don't (yet?) work. And the mulitlanguage part would be really really awesome. Most sites we build are multilang, so this feature would be almost a must-have, rather than a nice-to-have. Did you post your module to the official PW module directory? https://modules.processwire.com/add/ That way, it would be easier for other people to find your module. And (afaik) this is a pre-requisite if you want people to use the "check for updates" feature in the PW-backend. Zelim ti lep vikend ? 2 Link to comment Share on other sites More sharing options...
OLSA Posted August 18, 2018 Author Share Posted August 18, 2018 Zdravo Dragane, I totally agree with you, and I'm aware of all imperfections, but I use it last 2 years in all my projects (multilanguage) and it's play important role in all of them. News is that I am started with development of different version of that module and it's possible that I will include all suggestion in that version, or will do that in next release of current version, and after it post it to Github and in PW module directory. Inputs like text and textarea are multilanguage, but labels are not because that part depends on jQuery FormBuilder plugin (in my case, I write labels in administration default language). I really appreciate all the suggestions to make this module better and thanks for that! 1 Link to comment Share on other sites More sharing options...
dragan Posted August 24, 2018 Share Posted August 24, 2018 (edited) Evo me opet ? I encountered a strange problem today when I wanted to setup something with required fields: I first hit the module's save-button, then I hit the PW field-save button. And PW can't save the field, because I get errors from the first field that is required (I don't want to prepopulate the fields or use placeholders). This is some kind of a Catch-22 problem I guess ? And also, I see JS errors in Chrome console: When I want to edit a page where I have this field inside, Tracy reports this error: ErrorException: count(): Parameter must be an array or an object that implements Countable in /home/sitecom/www/mysite/site/modules/FieldtypeConfigForm/FieldtypeConfigForm.module:69 Stack trace: #0 [internal function]: Tracy\Bar->Tracy\{closure}(2, 'count(): Parame...', '/home/zeixcom/w...', 69, Array) #1 /home/sitecom/www/mysite/site/modules/FieldtypeConfigForm/FieldtypeConfigForm.module(69): count(Object(stdClass)) #2 /home/sitecom/www/mysite/wire/core/Wire.php(389): ProcessWire\FieldtypeConfigForm->___formatValue(Object(ProcessWire\Page), Object(ProcessWire\Field), Object(ProcessWire\ConfigForm)) #3 /home/sitecom/www/mysite/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___formatValue', Array) #4 /home/sitecom/www/mysite/wire/core/Wire.php(413): ProcessWire\WireHooks->runHooks(Object(ProcessWire\FieldtypeConfigForm), 'formatValue', Array) #5 /home/sitecom/www/mysite/wire/core/Page.php(1436): ProcessWire\Wire->_callHookMethod('formatValue', Array) #6 /home/sitecom/www/mysite/wire/core/Page.php(1364): ProcessWire\Page->formatFieldValue(Object(ProcessWire\Field), Object(ProcessWire\ConfigForm)) #7 /home/sitecom/www/mysite/wire/core/Page.php(1116): ProcessWire\Page->getFieldValue('setup') #8 /home/sitecom/www/mysite/wire/core/Page.php(1600): ProcessWire\Page->get('setup') #9 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/panels/RequestInfoPanel.php(470): ProcessWire\Page->getFormatted('setup') #10 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(159): RequestInfoPanel->getPanel() #11 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(108): Tracy\Bar->renderPanels() #12 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/TracyDebugger.module(1487): Tracy\Bar->render() #13 /home/sitecom/www/mysite/wire/core/Wire.php(383): TracyDebugger->sessionHandlerDBAjaxFix(Object(ProcessWire\HookEvent)) #14 /home/sitecom/www/mysite/wire/core/WireHooks.php(825): ProcessWire\Wire->_callMethod('sessionHandlerD...', Array) #15 /home/sitecom/www/mysite/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessWire), 'finished', Array) #16 /home/sitecom/www/mysite/wire/core/ProcessWire.php(603): ProcessWire\Wire->__call('finished', Array) #17 /home/sitecom/www/mysite/wire/core/ProcessWire.php(499): ProcessWire\ProcessWire->__call('finished', Array) #18 /home/sitecom/www/mysite/wire/modules/Process/ProcessPageView.module(254): ProcessWire\ProcessWire->setStatus(16) #19 /home/sitecom/www/mysite/wire/core/Wire.php(380): ProcessWire\ProcessPageView->___finished() #20 /home/sitecom/www/mysite/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___finished', Array) #21 /home/sitecom/www/mysite/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageView), 'finished', Array) #22 /home/sitecom/www/mysite/index.php(56): ProcessWire\Wire->__call('finished', Array) #23 {main} Any ideas? Did you ever stumble across such a situation? Edited August 24, 2018 by dragan added Tracy Debugger error msg Link to comment Share on other sites More sharing options...
OLSA Posted August 26, 2018 Author Share Posted August 26, 2018 Hi Dragane, sorry for the delayed response (I am on vacation until September 1st). If that's JS errors are in Chrome console inside field setup, that might be in relation with required attribute and Chrome browser (here are more details), but if you insert any values in setup "form" fields maybe you can "skip" that and PW will save field and it's subfields? Also, as a result of the first , maybe you have "empty" field (without subfields), and that cause second error (never noticed before, but I'll investigate that). Here is one important detail that you probably didn't notice, and my fault because I didn't mention, required attribute is not in use in current version. There are few options and buttons what are not in use and I didn't remove because my first plan was to use them all for fields (eg. "Required", "Limit access..." ) or for new features. Link to comment Share on other sites More sharing options...
Macrura Posted September 22, 2018 Share Posted September 22, 2018 This module is great, very useful and i'm using it on a project; I guess my PHP version (7.2.10 ) doesn't like this: (FieldtypeConfigForm, line 69) if(count($values)){ but this works if(wireCount($values)){ 2 Link to comment Share on other sites More sharing options...
jploch Posted September 27, 2018 Share Posted September 27, 2018 Hey! Thank you for this great module, I use it as part of a repeater item (for settings, to save some white space and grouping the settings). Now I tried to echo the Value of a select option (Dropdown) like this: {$item->grid_settings->gridsize->title} gridsize is the name of my select field. And grid_settings is the name of my ConfigurationForm field (which contain multiple select fields). Item is the repeater item. But this is not working. What Iam missing here? Also is it possible to preselect an option? Link to comment Share on other sites More sharing options...
OLSA Posted September 30, 2018 Author Share Posted September 30, 2018 Hello @jploch in case of select field, you can get only selected option value (and not title/text) or in your case: $grid_size = $item->grid_settings->gridsize; Link to comment Share on other sites More sharing options...
OLSA Posted September 30, 2018 Author Share Posted September 30, 2018 On 9/27/2018 at 2:22 PM, jploch said: Also is it possible to preselect an option? Preselect option, currently, only in case when you have option value as null "0", as example your "gridsize" field: Label: "Grid size" -- option value: 0, option text: Default -- option value: 1, option text: Grid size 1 -- option value: 2, option text: Grid size 2 In that case, preselected value in admin backend would be "Default". Later in your code: if ($item->grid_settings->gridsize){ // not default (not preselected value) ... } else { // default ... } But there is and "mix" variant, example, some select field with name background: label: "Background color" -- option value: 0, text: Default -- option value: black, text: Black -- option value: orange, text: Orange * preselected text : "Default" Later in code: <?php // configuration form field "settings" with select subfield "background" $background = $page->settings->background ? '-' . $page->settings->background : ''; ?> <div class="bgn<?php echo $background;?>"> * div can have css class values: bgn, bgn-black, bgn-orange Regards. 1 Link to comment Share on other sites More sharing options...
maxa11an Posted February 21, 2019 Share Posted February 21, 2019 Really like this module, using it to make a visual builder however I encountered that the uploading of files doesn't work. No errors is thrown. It starts the ajax-upload but when it should be done it just disappear and the file isn't uploaded. Currently debugging the issue. Will get back as soon as I find the issue. But also wanted to see if anyone else encountered this? Link to comment Share on other sites More sharing options...
gmclelland Posted February 21, 2019 Share Posted February 21, 2019 Sorry, above it says: Quote Do not place/use field type "Button" or "File input" because it won't works . Link to comment Share on other sites More sharing options...
maxa11an Posted February 21, 2019 Share Posted February 21, 2019 Just now, gmclelland said: Sorry, above it says: Yes, I just read that! I'll dig into solving that ? Link to comment Share on other sites More sharing options...
MilenKo Posted July 6, 2019 Share Posted July 6, 2019 @OLSA Hey man, I just found your amazing module while looking for an easy way to add a bunch of settings to a Profile Configuration page and I am trully impressed. I've seen some other great modules which I initially planned to use but to have a drag&drop functionality would make the development much easier for me (maybe I am too lazy). I am testing it now and will see how will it work. At least I can combine the file upload/image uplad default PW fields with the "custom field" of your module and avoid the need of adding image paths etc. Thank you for this masterpiece! 1 Link to comment Share on other sites More sharing options...
MilenKo Posted July 6, 2019 Share Posted July 6, 2019 After a few quick tests, I found it pretty straight forward to echo the content of text/textarea. In addition to the present functions of the module, it would be great if we could set the default state of the field (open, closed) as well as to have some logic of fields appearance based on other fields value (like it is with regular fields) Link to comment Share on other sites More sharing options...
MilenKo Posted July 31, 2019 Share Posted July 31, 2019 On 9/21/2018 at 9:32 PM, Macrura said: if(wireCount($values)){ I had a similar issue, but in my scenario (with no module modifications) the line causing it was 58 if(count($values)){ I can confirm that changing the line to @Macrura correction eliminated the error in my logs. 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