Jump to content

gebeer

Members
  • Posts

    1,560
  • Joined

  • Last visited

  • Days Won

    49

Everything posted by gebeer

  1. I reinstalled the module to make PW know that it is not autoload anymore. Now $this->addHookAfter('Page::render', $this, 'addInlineScript'); is not executed anymore. Doesn't matter whether I call it from init() or render() This confirms for me that modules need to be autoload in order to place hooks in them, like the wiki suggests. I guess I need to find another way of implementing my logic... But thanks again for your help.
  2. Thank ou for the quick reply. Maybe there is some misunderstanding here. I don't want to make a function ___hookable that is part of my module. I want to add an after hook to Page::render where I call my method 'addInlineScript': $page->addHookAfter('render', $this, 'addInlineScript'); This hook call I placed inside the render() method of my module. In the meantime I found out that the hook gets called when I place it in init() method of my module. But I don't want to call it from init() because the 'addInlineScript' method depends on some property that is created in render(). So I need to call the hook from there. The exit() is just there to confirm that my method gets called. I don't want the module to be autoload. I just understood from the wiki that it needs to be autoload in order to call a hook from within it. But I guess I got this wrong. So I made the module none autoload again but it is still being loaded. Has this to do with module cache and how can I make it not autoload again?
  3. Hello, I have a hook in a custom method of a non autoload module and it is not calling my hook method. In the wiki I read Modules that are intended to attach hooks in the application typically should be autoload because they listen in to classes rather than have classes call upon them. If they weren't autoload, then they might never get to attach their hooks. Does this mean that hooks are only working in autoload modules? I added 'singular' => true and 'autoload' => true to getModuleInfo() but still my hook funktion does not get called. My hook call at the end of this render method $this->inlineScript = $inlineScript; $page->addHookAfter('render', $this, 'addInlineScript'); $page object is available. Also tried $this->addHookAfter('Page::render', $this, 'addInlineScript'); and my hook method public function addInlineScript($event) { exit("gbr"); // $value contains the full rendered markup of a $page $value = $event->return; $value = str_replace("</body>", $this->inlineScript . "</body>", $value); // set the modified value back to the return value $event->return = $value; } Why is this not working? Any help would be much appreciated.
  4. I agree. Added all available providers to the select dropdown and have set OpenStreetMap.Mapnik as default. Will post the next days with update on awesome icons...
  5. That's true. But if your instruction go something like: "You need to include these 4 scripts in your head tag to make this module work and you need to download them from these 4 different places first", it may drive people off. Imagine a developer who cares about page loading optimization and he cannot do it right because of your module. Or he has to go and alter the module code so it fits his needs. Wouldn't it be better if the module followed commonly accepted best practices and people who use the module don't need to care about things like manual script inclusion? I personally don't feel really comfortable with the proposed approach 3, too. The $this->config->scripts->add() method seems to be the preferable way to go. But then you need to instruct the users of your module to include the necessary php for rendering the scripts tags before </body>. Which I consider to be a PW best practice anyway when it comes to conditional loading of scripts. The only point that I really wanted to make is that we should follow best practices and include our scripts at the end of the page and not in the head. If this limits developers freedom, it at least forces something on them that is generally a good thing.
  6. I came across this thread while working on my first PW module that needs to load quite a lot of scripts. So I am going to revive this thread because the OP makes an important point here: how to best find the balance between easy module integration and freedom for PW users when it comes to template structure . In my opinion, best practices for script inclusion should also be considered here. So while giving users the most possible freedom in how to structure their templates, they should at the same time be made aware of ways how to best implement script loading. Not only with PW, but in general. I for myself am still learning a lot about web development best practices while developing sites with PW. There is a lot of useful information to be found here in the forums which is absolutely great. One thing that most of web devs seem to agree upon is that loading scripts at the end of your template just before </body> increases site loading speed and thus user experience. Besides that it also makes sure that the DOM is already available to those scripts. And here lies the culprit of approach 3 proposed by the OP: all additional scripts get loaded in the <head> which slows down page loading time. Thus I would implement the addScripts method like this public function addScripts($event) { $page = $event->object; // don't add this to the admin pages if($page->template == 'admin') return; //other mechanisms to ensure the script only loads when this module was called in the front-end $additionalScripts = '[myScripts...]'; $event->return = str_replace("</body>", $additionalHeadScripts.'</body>', $event->return); } Only drawback I can see: following this approach, the module developer has to make sure that all inline scripts wait for the scripts they depend upon before they are executed (eg with $(window).load or $(document).ready)
  7. Thanks again for the port to leaflet! I prefer OSM over google maps and have been using it for quite some time. Leaflet is very powerful and opens up many possibilities. I forked Mats' module and added support for leaflet-providers so we can choose different map tile providers (see my post here). It is still a work in progress but seems stable. Once it is ready for production I'll make a pull request. Mats, do you think we should use leaflet-providers as standard or offer the user a choice whether they want to use it or not? Next up I will add an icon field and support for Leaflet.awesome-markers.
  8. @Mats thank you so much for your OSM version of the module. Have you opened a thread dedicated to it, yet? Couldn't find it in the forums. I forked your module and added basic support for leaflet-providers. In the field settings we can now choose the map tile provider. and the map renders accordingly (example with MapQuest.Open) (example with OpenStreetMap.BlackAndWhite) I'm thinking adding this on a per marker basis also but I'm not quite sure yet if it makes sense at all to define tiles per marker? We should definitely open a separate thread for your module, what do you think?
  9. I just noticed that I get the error on my vagrant box with latest stable 2.5.3. The error was related to wrong apache user/group in my vagrant box and previously I had solved it like this. But dev versions 2.5.26 and 2.5.27 don't throw this error anymore.
  10. Thank you for your patience with an OOP noob. I don't know how I would copy the array to my module. So some example code would be great. So that I can go on from there with removing keys etc.
  11. How can I access $defaultMarkup from within my hook: public function init() { $this->addHookBefore('Page::render', $this, 'addTooltipJS'); $this->addHookBefore('InputfieldWrapper::render', $this, 'addTooltip'); } public function addTooltip(HookEvent $event) { $defaultMarkup = ; $event->return; }
  12. That is a beast, indeed. And I'm quite new to PW modules. Have read the documentation. But don't no how to access $defaultMarkup in this case. The $event->object is of type InputfieldForm with lots of protected and private properties. Any help would be much appreciated.
  13. @LostKobrakai Thank you. I already had a look at InputfieldWrapper.php and am currently trying to add my hook there. Will report back with results or questions.
  14. I have searched the forum and google but couldn't find anything related. I want to show all field descriptions in admin forms as tooltips. Has this request really not come up before? I imagine a module that hooks into the Inputfield class, adds the description as title value to the inputfield and then makes use of https://jqueryui.com/tooltip/. Am I on the right track here? EDIT: I made a module "InputfieldHookAddTitle": <?php class InputfieldHookAddTitle extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Inputfield Hook Add Title', 'version' => 100, 'summary' => 'Adds title attribute to inputfields with field description as value', 'singular' => true, 'autoload' => true, ); } public function init() { $this->addHookBefore('Inputfield::render', $this, 'addTitle'); } public function addTitle(HookEvent $event) { $inputfield = $event->object; if ($inputfield->description == "") return; $inputfield->setAttribute('title', $inputfield->description); $event->return; } } This adds title attribute with value description to inputfields. Now I need to get rid of the original <p class="description"> tag which is set in the constructor method. How would I unset this? I don't see a unset method. And how do I add the Jquery tooltip js? EDIT: I managed to add the custom JS to the admin pages, thanks to Soma's blog post. In my site/templates/admin.php I added: // add tooltip JS to admin pages $modules->get('JqueryCore'); $modules->get('JqueryUI'); $config->scripts->add($config->urls->templates . "js/admintooltips.js"); and the admintooltips.js $(function() { var tooltips = $( "[title]" ).tooltip({ position: { my: "left top", at: "right+5 top-5" } }); }); Now I only need to get rid of the original description. Any pointers would be much appreciated.
  15. I made this into a blank site profile. Download and instructions here. Tested on a new PW install and it is working fine. Maybe some of you want to test it in other environments and let me know if I need to amend the README. Thank you.
  16. This is very inspiring. Thank you for sharing! Before I sit down and do this, do you have any plans on releasing this as a site profile? Edit: OK, I sat down and am working on it. Going smoothly so far. Will report back...
  17. @Soma I am sorry, didn't mean to flood the forum with this. Was just exited about the whole thing and that maybe made me go a bit far... Your proposed solution for setup and custom selector to get this working with pages that don't share the same tree is great. Very much appreciated. I put something together quickly to have the same functionality in a frontend form with the help of a jQuery plugin.
  18. @Soma that looks great! I am only having trouble understanding where exactly I need to put the "select_page" field and what the selector for this one would be. Because I am not sure what "options pages" refers to. Are these the area and event pages in your example? EDIT: I got it working now for my scenario. Thanks again. -destination template with title and country single page select field -tour template with title, country field and a destinations multi page select field with custom selector "country=page.country, select_page!='', template=destination"
  19. Your welcome. This is just on a playground site at the moment and will not be online until much later this year. But the code I posted is working for me.
  20. I am currently looking into dependent select fields or cascading select fields (as they are sometimes called), too. So I have a quite similar scenario as yours. I already have setup some working code that I want to share here. For a better understanding about my scenario: 1. parent countries with list of all countries 2. parent destinations, each destination gets assigned one country through "countries" pages asm select field. 3. parent tours, each tour gets assigned 1 or more countries through "countries" field and 1 or more destinations from "destinations" pages asm select field In tours form, when countries are selected I want to filter the destinations field to only show destinations of the previously chosen countries. For my solution I am using this jQuery plugin. So you need to call this in your template. My code is still a work in progress and written around my requirements but should be fairly easy to transfer to other contexts. Template code <?php // do not load _main.php for ajax requests if($config->ajax) $useMain = false; // provide dropdown data for the ajax request if ($input->post->depdrop_parents) { $ids = $input->post->depdrop_parents; $params = $input->post->depdrop_params; $options = []; $option = []; if (count($ids) == 1) { // only 1 id $pages = $pages->find("template=$params[0], countries=$ids[0]"); } // todo else { handle multiple ids} foreach ($pages as $page) { $option["id"] = $page->id; $option["name"] = $page->title; $options[] = $option; } echo json_encode(['output'=>$options, 'selected'=>'']); } // render the form if (!$config->ajax) { $content = ""; $destinations = $pages->find("template=destination,sort=countries.title"); $options = []; $option = []; // build options array for first select field: this is very specific to my scenario foreach ($destinations as $destination) { if (seekKey($options, $destination->countries->first()->id) == $destination->countries->first()->id) continue; $option["value"] = $destination->countries->first()->id; $option["name"] = $destination->countries->first()->title; $options[] = $option; } $content = "<form> <select id='parent' name='countries'>"; foreach ($options as $option) { $value = $option["value"]; $name = $option["name"]; $content .= "<option value='$value'>$name</option>"; } $content .= "</select>"; $content .= "<select id='child-1' name='destination'> </select>"; // need hidden input with value "destination" to populate params for the JS plugin // with the value that will be used as template value above in line 14 $content .= "<input type='hidden' id='dest' value='destination'> //todo submit button and logic </form>"; } In my functions.inc // Find the value in a multidimensional array function seekKey($haystack, $needle){ $output = ""; foreach($haystack as $key => $value){ if($value == $needle){ $output = $value; }elseif(is_array($value)){ $output = seekKey($value, $needle); } } return $output; } Javascript $(document).ready(function () { $("#child-1").depdrop({ url: './', depends: ['parent'], params: ['dest'], initialize: true }); }); Hope this helps.
  21. @Soma Thank you for clarifying I was thinking of it as an extra field type because "parent=page.anotherpageselect" is only working for pages that live under the same parent like you explained here. I'd need something more flexible that can be applied to page select fields whose pages have different parents. Meanwhile I posted about this in Wishlist&Roadmap.
  22. Hello, I am not so new here anymore but still very excited to get to know PW and all the forum users

  23. @adrian Thanks for the pointer. I had already found that here. But as Soma points out it only works for pages that are nested under the same parent. I would need something like this for page select fields that live under different parents in the page tree. My use case: 1. parent countries with list of all countries 2. parent destinations, each destination gets assigned one country through "countries" pages asm select field. 3. parent tours, each tour gets assigned 1 or more countries through "countries" field and 1 or more destinations from "destinations" pages asm select field In tours form, when countries are selected I want to filter the destinations field to only show destinations of the previously chosen countries. Destinations cannot live under countries because I need them under a separate parent where the user can add destinations easily without having to drill through the 249 available countries and search for the right one where they want to add their destinations under. What I think would work in theory: An inputfield type that lets you define which select fields in a template depend on each other and what the hierarchy of those fields is. This inputfield type adds the JS logic to the template form that will get the option values for the dependent select fields via AJAX call and fills them. The PHP of the inputfield type holds the logic to retrieve the right pages for the AJAX request. There are jQuery plugins like this or this available that could be used. Or the JS that is already there when using selector "parent=page.otherpagefield".
  24. @kongondo Thank you for pointing me to that one. But it doesn't do what I need and what Ryan is demonstrating in his introduction video to Select Multiple Transfer module: one select field that gets filled based on the previously selected option in another select field. I just posted about this in Wishlist&Roadmap. Maybe we better continue there because I think this is kind of going beyond the scope of this thread?
  25. In the thread for the Select Multiple Transfer module Ryan mentions that he used "dependent selects" for his introduction video: I searched the dev code and the forum up and down but can't seem to find this fieldtype. Has development been discontinued? I would really love to see that fieldtype in PW and would even be happy to pay for it if it was published as a pro field. I switched over to PW from Joomla/Seblod and they have a fieldtype called "Select Dynamic Cascade" that does just that.
×
×
  • Create New...