Jump to content

gebeer

Members
  • Posts

    1,386
  • Joined

  • Last visited

  • Days Won

    39

Everything posted by gebeer

  1. gebeer

    Web based IDE

    When it comes to working in teams, web IDEs can be great. I have some experience in team work on cloud9. And I am quite impressed about what features even their free account has to offer. If you are travelling a lot, you'll have your web IDE workspace setup available anywhere which is also great. Apart from that I prefer working on a local setup.
  2. Happy New Year to everyone! For a project that I'm working on, I needed to have dependent checkboxes on page edit forms in the admin. Just like dependent selects but for checkboxes. I couln't find anything and decided to write my first Inputfield module. I have only tried it on PW > 3.0. But it should also work on the 2.x branch. Would be great if some of you could try it out and give some feedback. You can find the module InputfieldDependentCheckboxes at github Here's some screenshots of the module in action and instructions on how to use it. ##An Inputfield for ProcessWire admin interface that handles the display of dependent checkboxes in page fields Sometimes we need checkboxes to depend on other checkboxes in our page edit forms. This module adds this functionality to standard page field checkboxes for 2 or more checkbox fields. ## Installation 1. Copy all of the files for this module into /site/modules/InputfieldDependentCheckboxes/ 2. In your admin, go to the Modules screen and click "Refresh". Under the 'Inputfield' section, install the 'InputfieldDependentCheckboxes' module. 3. Open Modules->Configure->InputfieldPage. Under 'Inputfield modules available for page selection' add 'DependentCheckboxes' from the select dropdown and submit ##Field Setup This inputfield extends the standard checkboxes for page fields. Therefore you need to have page fields configured already that you can extend with this Inputfield type. ###Prerequisites You need to have at least 2 fields of type page that have 'Checkboxes' defined as Input field type and live on the same template. A real world example: There are different types of instructors. Each instructor type can have multiple different certifications. For this to happen, we need 2 page fields (multiple): A) instructor_types: lists pages with template 'instructor_type' B) certifications: lists pages with template 'certification' The certification template needs to have the instructor_types page field to assign one or more instructor_types to a certification. ###Setup (link checkbox fields) 1. Edit your page field A and go to the 'Input' Tab. Under 'Input field type' choose 'DependentCheckboxes'. Hit save. Now under 'Choose the target checkboxes field' choose the name of your field B. Hit save again. 2. In your page field b make sure to choose a template under 'Input' Tab under 'Selectable Pages'->'Template of selectable page(s)'. Your fields should be setup. If you now edit a page that contains the 2 fields, the dependent checkboxes should be working. EDIT: And yes, this is working for multiple dependent checkboxes, too. (I have tried it with 3 so far) Some notes on how the module works behind the scenes: - parent checkboxes (actors) that have dependent checkboxes (targets) get custom data attributes applied which contain arrays of the targets' IDs - some Javascript is initiated on acxtors and targets to handle the display based on the id arrays in the data attributes. EDIT: since this module's mention in ProcessWire Weekly it might get some more attention. I just wanted to point out that it is still in alpha state. I will continue development and more thorough testing while implementing it in an ongoing project within the next 3-5 months or so. I will eventually release a stable version then. If you use the module with only 2 dependent checkbox fields, it should work smoothly. There are still some quirks when using 3 or more and I need to figure out how to best resolve them. So please be patient (or jump in with ideas ).
  3. Kind of solved. I decided to refactor my module code and replace the original render() method instead of the addOptions() method of InputfieldCheckboxes module. This way I can access my settings values inside the render method and make use of them further down the road.
  4. @ryan thank you for the insight. Problem is, that I need my config setting values to be available to the public function addOption($value, $label = null, array $attributes = null) {...} which replaces the original method in wire/modules/InputfieldSelectMultiple.module. And that method is called before renderReady(). I'm adding custom data attributes to the checkboxes using /** * Adds an option with extended attributes * Replaces original method in wire/modules/InputfieldSelectMultiple.module * taken from https://processwire.com/talk/topic/419-extending-inputfields/?do=findComment&comment=76823 * */ public function addOption($value, $label = null, array $attributes = null) { if(is_null($value) || (is_string($value) && !strlen($value))) return $this; if (null === $attributes) { $attributes = array(); } $extra_atts = $this->extendAttributes($value, $label); $attributes = array_merge($attributes, $extra_atts); return parent::addOption($value, $label, $attributes); } /** * Hook this and return an array with whatever extended attributes you need. * */ public function ___extendAttributes($id, $value) { /** * Either hook this method to do what you want or implement things directly if this * is the only use of this Inputfield. * For your example you'd grab the fields you want from your page and put into data * attributes... */ $atts = array(); $targets = array(); $deps = wire('pages')->find("template=certification, instructor_types={$id}"); foreach ($deps as $d) { $targets[] = $d->id; } $atts['data-icbdtargets'] = json_encode($targets); return $atts; } And I want to build the hardcoded selector in $deps = wire('pages')->find("template=certification, instructor_types={$id}"); from values that I get from the settings fields in getConfigInputfields(). If it is not possible at all I would have to create an extra configurable module that provides the settings. I'd like to avoid that overhead. My Inputfield module provides configurable dependent checkboxes. It is working with the hardcoded selector. But I want to release this as a configurable module so that people don't need to alter code in the module. It makes sense to have the settings in the 'Input" Tab of the field settings. So I would like to avoid the need of an extra module for config settings. I'm pretty new to module development and haven't grasped all concepts yet.
  5. Hello, I'm struggling to access module config values inside init() or ready(). My module extends InputfieldCheckboxes and implements Module interface. I have a custom configuration field public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $modules = $this->wire('modules'); $options = $this->getInputfieldCheckboxes(); $f = $modules->get('InputfieldSelect'); $f->attr('name', 'targetField'); $f->set('label', $this->_('Choose the target checkboxes field')); $f->set('description', $this->_('The field that has checkboxes which depend on this field\'s checkboxes')); // $f->set('notes', $this->_('Types indicated with an asterisk are for multiple field selection.')); foreach ($options as $fieldName => $prop) $f->addOption($fieldName, $prop['label']); $f->attr('value', $this->targetField); $inputfields->add($f); return $inputfields; } This is working fine and saving values. Right after getModuleInfo() I have public function __construct() { parent::__construct(); $this->set('targetField', ''); } In my render() and getConfigInputfields() methods, I can access the value for the custom config setting with $this->targetField. But in other methods, it is not available. In the API Reference for init() it says: When I remove my __construct() method entirely, config values still get saved correctly. But when I access $this->targetField in init() or ready(), I get null. How can I access configuration data inside init() or ready() ? I read many posts and looked at how other modules do this. But couldn't find a solution. Thanks in advance for any pointers.
  6. Hello and Happy New Year to everyone, I'm trying to implement module configuration fields in an Inputfield Module following Ryan's blog post https://processwire.com/blog/posts/new-module-configuration-options/ Is this supposed to work for all modules? My module extends InputfieldCheckboxes. This is the structure of my module folder: The InputfieldCheckboxesDependenciesConfig.php is not being picked up at all. When I configure it the old way with ___getConfigInputfields(), it is working.
  7. @lena In the module docs you can find instructions on how to apply your custom markup/classes: https://github.com/justb3a/processwire-simplecontactform/blob/master/doc/overwrite-classes-and-markup.md EDIT: and welcome to the forum!
  8. @Can thanks a ton for this hint. Looks promising and I will definitely give it a try.
  9. Thank you for the explanation. Is it possible then to instantiate the InputfieldCheckboxes class in the original context from within my module so that I have access to all methods? Or any other way to "step inside" the original class context?
  10. Hello, I need to add some markup to checkbox inputs of page fields in the admin forms for which I created an autoload module with $this->addHookBefore('InputfieldCheckboxes::render', $this, 'renderCheckboxes'); The renderCheckboxes method aims to replicate, extend and then replace the original render method of InputfieldCheckboxes. I'm having trouble finding the right class context from within my renderCheckboxes method. In the original render method there is code like $this->checkDefaultValue() where $this represents the context of ProcessWire\InputfieldCheckboxes and checkDefaultValue() is a method defined in the parent class InputfieldSelect. In my renderCheckboxes method, I need to be able to access the same class context in order to replicate the original render method. public function renderCheckboxes($event) { $inputfield = $event->object; if($inputfield->name != 'certifications') return; var_dump($inputfield); $inputfield->checkDefaultValue(); } The var_dump tells me that $inputfield is an object instance of ProcessWire\InputfieldCheckboxes, just like $this in the original render method. But when I try to do $inputfield->checkDefaultValue(), I get an error: Method InputfieldCheckboxes::checkDefaultValue does not exist or is not callable in this context This tells me that the context for the $event->object is not the same as for $this in the original render method. Obviously I don't know enough about OOP and PW module development to understand what is going on. But I would like to be able to replace that render method with my own. Any pointers on how to achieve this would be very much appreciated.
  11. OK, I see. So I might be better off editing in a modal. Thanks for the insight.
  12. @adrian works like a charm, thank you! @Robin S thank you for the suggestions and for the code! I have Lister Pro but I don't want to edit pages in a modal. But surely your code will come in handy for other projects. Much appreciated. Only thing that I still need to figure out is how to get the referring URL of the lister that the page was opened from for editing. $_SERVER['HTTP_REFERER'] gives me the edit URL of the page itself. Any ideas would be much appreciated.
  13. Hello, for quite a while I found it quite annoying that when you edit a page from a lister view and then save+exit you will end up at the page tree and not at the lister view where you came from. I haven't found a setting that lets you return to the lister view. I wrote a little hook that does just that for a project where I am using Lister Pro. The lister is called Events and has a fixed url. It lists only one type of pages with template event. Here's the working hook code that I placed in admin.php: // redirect to events list on save+exit wire()->addHookBefore('ProcessPageEdit::processSaveRedirect', function($event) { $id = (int) $this->input->post('id'); $page = wire('pages')->get($id); if($this->input->post('submit_save') == 'exit' && $page->template->name == 'event' && wire('user')->hasRole('member')) $this->session->redirect(wire('config')->urls->admin . 'events/'); }); Now I would like to make this more generic so that it works for any lister. How can I get the referring URL (other than from $_SERVER['HTTP_REFERER']) to use it instead of the hardcoded URL I have now in the redirect? And is there any way that I can access properties of the instance of ProcessPageEdit that called processSaveRedirect? The $event->object is the processSaveRedirect method and $this is ProcessWire. How can I access properties of ProcessPageEdit? E.g. $id or $page. ATM I am getting the page id from the $input->post. Obviously I am not a savvy PHP OOP dev and have no idea how to do such things in a proper way EDIT: I know I could open pages from the lister view in a modal to avoid having to redirect. But I don't want to use that option. $_SERVER['HTTP_REFERER'] gives me the URL of the page that I edited and not the URL of the lister.
  14. @arjen When I was looking 2 days ago I couldn't find it either. @BitPoet I agree. In the docs it says only sort order not index and we can use some PHP to get the index. This code works for me: foreach ($homepage->children as $key => $child) { $sortIndex = $key; // or $key + 1 if you don't want to start with 0 }
  15. Thanks @arjen According to this thread and Soma's post here it should work. But I'll try your code or a foreach($homepage->children as $key => $child) {} and post back results here.
  16. Hello, on a brandnew 3.0.35 install, I get wrong results for $page->sort. My structure is like Home -level1-1 -level2-1 -level2-2 -level2-3 -level1-2 -level1-3 When I do foreach($homepage->children as $child) { echo $child->sort; } It gives me: 3, 4, 5 where it should be 0, 1, 2. When I loop through the children's children, the values are correct foreach($homepage->children as $child) { foreach($child->children as $ch) { echo $ch->sort; } } returns 0, 1, 2. On level1 there never where more than 3 pages. So I don't know why it possibly could be starting with 3 instead of 0. Is there any way to recreate the sort index? I tried moving level1 pages around in admin but that didn't change anything. EDIT: I also tried $homepage->children('sort=sort'). Same results.
  17. To follow up on this, it would be very much appreciated if the render functions were hookable. I need microdata in the markup for the comment lists ratings. I know I could loop through the comments and output my own markup. But it would be much better if I could place this in a module and hook from there as I (and maybe others) sure could use this on other projects, too. EDIT: I added an issue and a pull request on github.
  18. @mr-fan if you are still having the problem from with geocoding from your custom fields, maybe my modified InputfieldLeafletMapMarker.js gist can help. I have a custom button in the form that triggers the geocoding, defined on line 48 and a fucntion from line 135 that takes values from custom fields, concats them and does the geocoding.
  19. @netcarver Awesome work, thank you so much for sharing!
  20. Is this service still up and being maintained? On https://lightning.pw/ I get for 2 days now.
  21. @cstevensjr Got your point and totally agree with what you're saying. I didn't mean to force anybody into using preprocessors. Just wanted to encourage people to start looking into it because it really can make live easier...
  22. @cstevensjr I partly agree with you. And again thanks to @flydev for providing the precompiled version. But in a way this defeats the purpose of a sass based site profile.
  23. @Jim_Chapman Thanks for posting here. In the meantime my client has decided to go with native apps and we already have developers for the project.
×
×
  • Create New...