-
Posts
6,671 -
Joined
-
Last visited
-
Days Won
366
Everything posted by bernhard
-
[solved] How to add action buttons fieldtype for each repeater
bernhard replied to Federico's topic in General Support
$wire->addHookAfter('InputfieldText::render', function($event) { $field = $event->object; if($field->name != 'title') return; $repeaterBtn = $this->modules->get("InputfieldButton"); $repeaterBtn->attr("value", "Generate something"); $repeaterBtn->attr("type", $submitID); $repeaterBtn->attr("id+name", "btn"); $repeaterBtn->attr("href", "/admin/page/edit/?id=1"); $repeaterBtn->attr("target", "_blank"); $repeaterBtn->addClass("customClass"); $event->return .= $repeaterBtn->render(); }); btw: panels are a great alternative for new browser tabs: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/#using-internal-components-modules -
Hi @Jwenk and welcome to the forum, the preciser you ask your questions the better the answers will be What are you trying to do?
-
[solved] How to add action buttons fieldtype for each repeater
bernhard replied to Federico's topic in General Support
hey @Federico i didn't read all your code but I would hook the inputfield's render method of the field that is inside the repeater. or you create a runtime markup field with your code. that might be easier. the only thing you have to take care of when hooking yourinputfield::render() is that the $field->name is not the field's name only but it has some appended or prepended string (repeater name or id, not sure at the moment... you can easily check this with tracy). always start without any additional checks/ifs/returns and then continue step by step until you get where you want, for example this in your /site/ready.php: $wire->addHookAfter('Inputfield::render', function($event) { $field = $event->object; bd($field->name); }); then you can modify the hook to only execute when needed (like hooking InputfieldText instead of the Inputfield base class, doing a return when the field name does not match...). i think @Robin S came up with a good solution how to check for the right field name inside repeaters but i can't find where he mentioned it in the forum. this is another way of checking that i used, but maybe robin can show us the better way -
I'm sorry @modifiedcontent but I put a LOT of effort in the blogpost, so as long as you don't come up with preciser descriptions of what EXACTLY you are trying to do I can not help. Maybe someone else understands your needs better and can therefore help you better. maybe a google search for "dashboard" has some interesting reads for you: https://www.google.at/search?q=site:processwire.com+dashboard
-
hi modifiedcontent, this sounds a little strange. the easiest way of editing content is of course the normal pw edit screen. you can do a lot with normal pw features (like hiding fields on several conditions etc). if you really need more customized forms I show how you can do that here: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/#create-our-first-real-inputfields ; that's only one way of doing it. you can also easily modify the page edit forms via hooks. sorry for that. you can also start by using InputfieldRuntimeMarkup - maybe that's easier to begin with... totally up to you. you can create several pages in one module: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/#hello-page2 ; but you could also create one module for each page. It depends on you and your usecase which level of separation makes sense. sure, thats what i do throughout the tutorial. start with hello world, end with a custom CRM
-
[solved] How to add action buttons fieldtype for each repeater
bernhard replied to Federico's topic in General Support
hm... @dragan i guess the runtimemarkup field only has to return the "<button>" element (without the <li>, <div.InputfieldContent> and so on... you are right see this post for example (and the following): and also this: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/#using-internal-components-modules (scroll down to the buttons section) -
Nice one Canada should be adrian's territory - I hope they hired him
-
really nice feature introduced in november: live share (great way of collaborating with others!) https://code.visualstudio.com/blogs/2017/11/15/live-share ps: i don't want to abuse this thread for interesting stuff about vscode that is not related to processwire if that is not wanted...?
- 246 replies
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
@SamC great. Maybe you want to use less.js (http://lesscss.org/#using-less-third-party-tools) to show a very simple way of playing around with the admin themes LESS files? We could even build a theme generator using less.js and/or AIOM's php based less parser... Changing colors of the theme should be a lot easier than downloading source files, compiling everything, uploading...
-
hi @theoretic this looks very nice. I'm just not sure about the blue link color... I think the main problem is that there is no guide at all of how to customize the uikit theme properly. Maybe you could share what we have to do in a tutorial?
-
hi suntrop, I don't know why and I don't know if this is the best option (hooking is for sure also fine, or even better), but I like to create custom endpoints in the admin for that purpose via a ProcessModule. There i create an execute method (like executeMycustomcopyfunction) so that you can call this endpoint easily like this: <a href="/admin/page/mymodule/mycustomcopyfunction/?pagetocopy=123&newparent=456©children=1">copy to new parent with children</a> In this method you can do whatever you want (don't forget to check permissions if that's important in your case). Somehow I found this way easier than hooking One drawback could be that you need to check if the page has some unmodified changes. I use my clone link on an overview-table so thats no factor in my case since the page is not being edited when clicking the clone link.
-
Module: AIOM+ (All In One Minify) for CSS, LESS, JS and HTML
bernhard replied to David Karich's topic in Modules/Plugins
The module supports less, you can also define variables there -
Ok sorry i shut up since I don't have a clue about this module
-
of course you can! just clear your post data and redirect to the same page. If you do not show the submitted data, then this works (for example if you had a general "thanks for your message"). if you want to show data to the user (like "thanks alan for your message, we'll contact you soon") you could save that data to $session and display it from the session variable after clearing the post data. edit: actually the post data should get cleared already by the redirect
-
I have never used this module so I don't know how it works but your problem can easily be solved by a redirect: https://stackoverflow.com/questions/3923904/preventing-form-resubmission
-
If I remember correctly unpublished repeater pages get cleaned up by processwire at some time interval (I think one day or so). Would that explain your situation?
-
no clear all your unnecessary server and client cache+sessions+cookies etc related to that site and try it again.
-
My first hook to customise the page title for a specific template
bernhard replied to LAPS's topic in General Support
that's exactly why using tracy is so great, because now you know that the hook did not execute it's the same for me. don't know why it is not executed. maybe it's a bug, maybe we are using the conditional hook wrong. I didn't use conditional hooks for a long time and sometimes hooks with if-statements are even easier to read. so it's totally up to you which one you use. -
My first hook to customise the page title for a specific template
bernhard replied to LAPS's topic in General Support
use tracy and debug $event: wire()->addHookBefore('Page(template=user)::changed(0:last_name, 1:first_name)', function($event) { bd($event); }); hookevents ($event) always have the object (class) and the arguments (parameters), in this case $event->object is the class ($page you are looking for) and ps: i prefer addHookAfter most of the time to be sure that the method itself does not overwrite the value again... don't know if that makes sense in your case but just wanted to point out that you have to take an eye on that. you see very well that $event->object = user, $event->arguments(0) = field name, (1) = old value, (2) = new value. it did only work for me like this: wire()->addHookBefore('Page(template=user)::changed(0:email)', function($event) { bd('user changed'); bd($event->arguments(0)); bd($event->arguments(1)); bd($event->arguments(2)); bd($event); }); id didn't work with multiple fields in the changed() part. don't know why. you can investigate this on your own with the help of tracy and some try&error. -
My first hook to customise the page title for a specific template
bernhard replied to LAPS's topic in General Support
no, but saveReady belongs to the pages class, so the template condition won't work. You could use Page(template=user)::changed(0:first_name, 1:last_name) i guess... but saveReady hooks with an if statement are totally fine -
My first hook to customise the page title for a specific template
bernhard replied to LAPS's topic in General Support
the if-statement is totally fine. you can also use conditional hooks: https://processwire.com/blog/posts/new-ajax-driven-inputs-conditional-hooks-template-family-settings-and-more/#new-conditional-hooks don't think that there is a best practice or any performance difference between conditional hooks and if statements but that's just a wild guess... -
My first hook to customise the page title for a specific template
bernhard replied to LAPS's topic in General Support
hi laps, i strongly recommend using tracy during development, then you can see instantly whats going on in most of the cases... $wire->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments('page'); bd('page title: ' . $page->title); }); just put this in your /site/ready.php and save any page you like and you'll see the output in your debug bar: just put it in your /site/ready.php file - you don't need to define anything else. Prepend and append files are for rendering the frontend. -
... Of all hookable methods that are executed. So when you save a page you would see all methods you can hook into in the right order... Save, saveready, saved...
-
That's not true and an unfair statement in this context. I agree that "no listed vulnerabilities" is no proof of security but it does also not mean that security is not a main goal. Security by obscurity definitely helps to protect us from lots of threats but it's definitely not the only and also not the most important part of the puzzle... https://processwire.com/docs/security/
-
Thanks adrian. I've never really used the debug tools as I didn't find them really helpful. Maybe I'm missing something and just don't know how to use them properly? But what I wanted to achieve with the hookrecorder was some kind of execution plan of all hookable methods. A list where you can see which method get's called after the other. Ideally it would also show some additional information (like which page was saved, wich arguments where provided...). Maye it would also be possible to have some kind of nesting in it? The result could be something like this: ProcessPageView::execute ProcessPageView::ready ProcessPageEdit::buildForm (id=mypageid, ...) InputfieldWrapper::render (name=myfield, ...) Inputfield::render (name=myfield1, ...) Inputfield::render (name=myfield2, ...) Inputfield::render (name=myfield3, ...) ProcessPageView::finished I have no idea if that Execution Plan is correct... I'm quite familiar with hooking all around and looking for the right hook in the code but still I don't know exactly WHAT is going on WHEN. But looking on sime kind of list like above everybody would instantly get what is going on and would get a tremendously better understanding of how pw works. Then one could go further and look into the related class' code and inspect it. This list could also show additional info, as I already mentioned. And what I mean is on the one hand information about some variables what is currently happening (like which field is going to be rendered etc.) and on the other hand maybe it could list all hooks that are currently applied to this method (similar to the hooks list of the debug tools, listing hooks by priority so that you instantly get an idea of what is going on). I think such a tool would not only be of HUGE help for newbies but also for experienced devs. For example you could have a problem with some kind of pagesave actions... you have a hook that should change the page title to "myval" after every pagesave... Pages::save (id=123) execute hook from file /site/ready.php on line 12: collapsed hook code [...] $page->title = 'myval'; [...] Pages::saveReady (id=123) execute hook from file /site/modules/mymodule.module.php on line 240: [...] $page->title = 'my wrong value'; [...] Pages::saved (id=123) no hooks executed you would instantly see what's going on and that there is a conflicting saveReady hook overwriting the page title. I hope you get my point now. Or maybe I should start using XDebug and that's exactly what it is doing? PS: The list of hooks we have in the debug tools seems to be a list of all active hooks? And the sorting order is not helpful for me - it is even confusing... Is there any system in the order they are presented?