Jump to content

gebeer

Members
  • Posts

    1,560
  • Joined

  • Last visited

  • Days Won

    49

Everything posted by gebeer

  1. 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.
  2. @BitPoet thanks for clarification.
  3. 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.
  4. @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!
  5. @Can thanks a ton for this hint. Looks promising and I will definitely give it a try.
  6. 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?
  7. 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.
  8. @LostKobrakai great idea, thank you!
  9. OK, I see. So I might be better off editing in a modal. Thanks for the insight.
  10. @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.
  11. 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.
  12. @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 }
  13. 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.
  14. 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.
  15. 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.
  16. @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.
  17. @netcarver Awesome work, thank you so much for sharing!
  18. Is this service still up and being maintained? On https://lightning.pw/ I get for 2 days now.
  19. @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...
  20. @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.
  21. @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.
  22. @flydev Thanks a lot for putting this together. I was only waiting for BS4 to reach beta state before I will update my site-pwbs profile. Now I don't need to spend the time on it myself, which is great @pwired @cstevensjr I can only recommend to preprocess yourself and encourage you to look into node, compass, bower etc. It really is worth the effort and gives you so much more flexibility. With the precompiled version of this profile, you need to override a lot of stuff in your own CSS and this will bloat your code.
  23. Not to forget ST3 SFTP and Sublimerge plugins. They cost little but bring huge benefits to my workflow
  24. Just wanted to throw PostCSS into the discussion. Seems to be the way to go for me. I've been working with SASS for the last 2-3 years now. With PostCSS it is easy to integrate my SASS workflow and further enhance it with PostCSS plugins like autoprefixer, media query packer, minification etc. So you don't really need to change your workflow and get to optimize output of your CSS. Here are 2 great articles that helped me with the conversion from native SASS compiler to SASS+PostCSS+gulp. After all I believe that CSS optimization and minification should be done on the client side. Preprocessors can assist here. And even concatenation will soon be a relic of the past when HTTP/2 fully hits the scene. benbyf has a great blog post with performance comparison http/1.1 vs http/2.
  25. @iNoize getting comments is not implemented in the module. One would have to extend the module code to call the comments endpoint for every media object. Sorry, but I don't have the time for this right now.
×
×
  • Create New...