-
Posts
1,554 -
Joined
-
Last visited
-
Days Won
48
Everything posted by gebeer
-
Replace render method of InputfieldCheckboxes - class context
gebeer replied to gebeer's topic in Module/Plugin Development
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?- 5 replies
-
- inputfield
- render
-
(and 1 more)
Tagged with:
-
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.
- 5 replies
-
- inputfield
- render
-
(and 1 more)
Tagged with:
-
Redirect to Lister after Save + Exit via Hook
gebeer replied to gebeer's topic in Module/Plugin Development
@LostKobrakai great idea, thank you! -
Redirect to Lister after Save + Exit via Hook
gebeer replied to gebeer's topic in Module/Plugin Development
OK, I see. So I might be better off editing in a modal. Thanks for the insight. -
Redirect to Lister after Save + Exit via Hook
gebeer replied to gebeer's topic in Module/Plugin Development
@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. -
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.
-
@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 }
-
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.
-
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.
-
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.
-
@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.
-
@netcarver Awesome work, thank you so much for sharing!
-
Is this service still up and being maintained? On https://lightning.pw/ I get for 2 days now.
-
@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...
- 39 replies
-
- 4
-
-
- responsive
- bootstrap
-
(and 3 more)
Tagged with:
-
@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.
- 39 replies
-
- responsive
- bootstrap
-
(and 3 more)
Tagged with:
-
@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.
-
@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.
- 39 replies
-
- 3
-
-
- responsive
- bootstrap
-
(and 3 more)
Tagged with:
-
Not to forget ST3 SFTP and Sublimerge plugins. They cost little but bring huge benefits to my workflow
-
Out of interest, who's using Less/Sass vs plain old CSS
gebeer replied to onjegolders's topic in Dev Talk
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. -
@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.
-
I have a setup where users can enter some Hanna Code in the editor which will be replaced by a gallery that contains all images on that page or a chosen number of images. This is my Hannacode PHP <?php $images = $page->images; // name of your images field if ($images->count) { $config->scripts->add($config->urls->templates . "bower_components/fancybox/source/jquery.fancybox.pack.js"); $config->styles->add($config->urls->templates . "bower_components/fancybox/source/jquery.fancybox.css"); $showcount = ($show == "all") ? false : $show; $gallery = "<article class='gallery row'>"; if($showcount) $images = $images->find("limit={$showcount}"); foreach ($images as $i) { $thumb = $i->size(300, 300); $desc = ($i->description) ? $i->description : $page->title; $gallery .= "<div class='col-md-4'> <div class='thumbnail'> <a class='fancybox' rel='group' href='{$i->url}'> <img src='{$thumb->url}' alt='{$desc}'> </a> <p class='caption'>{$desc}</p> </div> </div>"; } } $gallery .= "</article>"; echo $gallery; Hanna Code to insert into the editor: [[gallery]] // shows all images [[gallery show=6]] // shows first 6 images Settings in Hanna Code module With this solution users cannot choose the images for the gallery from within CKEditor but it takes images from the images field of that page. This should get you started. Obviously you'd need to adjust script paths and markup (I'm using Bootstrap 3 here)
-
Interesting solution, indeed. But it feels a bit hacky. I'd rather present a different menu layout to mobile devices as to avoid the hover problem in the first place. Something like off canvas or the likes.
-
Out of interest, who's using Less/Sass vs plain old CSS
gebeer replied to onjegolders's topic in Dev Talk
Susy is totally great. It might have a bit of a steep learning curve at the beginning. But once you have wrapped your head around it, it is a pleasure to use and the most flexible grid solution I have encountered so far. There's a ton of great resources out there that can help to grsp the concept. Good starting point: http://zellwk.com/blog/susy2-tutorial/ Flexbox is definitely worth exploring. Recently I discovered https://flexeble.space/ which is a flexbox grid with inline-block fallback for >= ie9. But since everything can be accomplished with Susy and browser support for flex is not yet fully there, I prefer to wait until it is nativel;y supported in Susy. And there seem to be good reasons why you shouldn't use flex for overall page layout: https://jakearchibald.com/2014/dont-use-flexbox-for-page-layout/ -
I'm using it for all my development work. Makes setting up dev environments so much quicker and easier. No more manual installation of LAMP stack in my Linux box or fighting with WAMPP/XAMPP settings. I have one vagrant box that hosts all of my PW projects. Then I have one that brings all I need for a Drupal project. My main box is a remnant from the days where I was mainly doing Joomla projects. But it still works quite nice: https://github.com/joomlatools/joomlatools-vagrant One of these days I want to put together a box solely for PW with wireshell etc. Just didn't have the time to pull it together. Bernhard put a nice box together with some scripts for automatic PW installation and DB backups: https://github.com/BernhardBaumrock/vagrant-pw-lamp
- 28 replies
-
- 4
-
-
- vagrant
- virtualbox
-
(and 1 more)
Tagged with:
-
Hello, I need to restrict the page view of my app to a single guest user. This means if a session for user guest is already open for that page, other guest users are not allowed to view the same page. $session doesn't help much in that case as far as I can see from the docs (or maybe $session->getHistory() can help?). I think I could approach it this way: 1. Set session storage to DB 2. Query session table in DB for open sessions for that page and act accordingly Is there anything built into the API which I have missed that I can utilize to query the session table? Or would I have to use $database and build my own query? Any insight on this or idea how to tackle the problem would be much appreciated.
- 1 reply
-
- session
- guest user
-
(and 1 more)
Tagged with: