-
Posts
6,671 -
Joined
-
Last visited
-
Days Won
366
Everything posted by bernhard
-
I highly recommend everybody to do that stuff in the backend. Creating an admin page is easy and there you can to exactly the same as you would do on the frontend: Write PHP, HTML, JS + CSS. The benefit you get is huge: You can use all the power of the PW admin framework, eg, MarkupAdminDatatable, InputfieldSelect etc.; You'll also learn a lot about ProcessWire. I'd not say what you plan is piece of cake, but it's for sure doable with PW ?
-
How to set Inputfield settings dynamically via code?
bernhard replied to bernhard's topic in General Support
Hi @kongondo I did not find a solution to this until now. I think there is none in general. InputfieldCkeditor has a custom implementation for that need var editor; if(typeof ProcessWire.config[configName] != "undefined") { var editor = CKEDITOR.replace(editorID, ProcessWire.config[configName]); } else if(typeof $editor.attr('data-configdata') != "undefined") { // allow for alternate option of config data being passed through a data attribute // useful for some dynamic/ajax situations var configData = JSON.parse($editor.attr('data-configdata')); ProcessWire.config[configName] = configData; var editor = CKEDITOR.replace(editorID, configData); } if(editor) { ckeInitEvents(editor); $editor.addClass('InputfieldCKEditorLoaded'); } So with CKEditor you can pass through custom settings via data-configdata. But that's also only related to the display part of the Inputfield. Regarding ajax processing on the backend I have not found any other way than setting the values directly in the DB (meaning to create a dedicated field for every different setting). I have not looked into how the template overriding feature for fields works. Maybe there is some hookable method that could be used to modify the settings based on the template just via code? https://processwire.com/blog/posts/pw-3.0.145/#field-template-context-override-settings If you find anything please let me know ? -
Unfortunately I'm not totally happy with the module as it is. One thing is the decimal issues shown by Lostkobrakai, the other thing is that in my setup the need has come up to list all revenue that have 20% vat etc.; This is at the moment not possible using this module, because the data is stored in json objects. While it would be possible to query the JSON directly in the DB with current mysql versions, the problem is also that those revenues can not easily be enriched with other data (like some tax codes or the like). So I need to rethink that module soon ?
-
Yes, RockLESS can send variables from PHP to LESS: $less = $modules->get('RockLESS'); $less->vars = [ 'foo' => 'bar', ]; $css = $less->getCSS($config->paths->templates . 'less/theme.less')->cssUrl; echo "<link rel='stylesheet' type='text/css' href='$css'>"; How you combine that with ProCache is up to you. You can either send the compiled CSS to procache or I think you could also generate a LESS file via plain PHP listing your variables and include that file via @include in your LESS and then parse that LESS via ProCache.
-
My top 3: TracyDebugger TracyDebugger TracyDebugger ? We already have such a thread here:
-
Thx for sharing your experience @psy ? mPdf is unfortunately not really a pleasure to work with ? It feels a bit like designing websites 20 years ago with lots of custom table layouts, custom styles, paddings, margins etc... But as you said: I also got there almost everytime and I didn't find a better solution yet. Writing your styles as LESS can be helpful because you can create simple custom classes for any element and to the complex styling in CSS. Using LESS ensures that your style stays easy to maintain because you can use class inheritance and variables. RockPdf plays really well together with RockLESS. I added an example to the readme: Combine RockPdf and RockLESS $pdf = $modules->get('RockPdf'); $less = $modules->get('RockLESS'); $style = " @padding-s: 10pt; .border { border: 1pt solid #afafaf; } .hello { .border; color: blue; padding-top: @padding-s; } .world { .border; color: red; padding-top: @padding-s * 2; } "; $css = "\n".$less->parse($style); $pdf->write("<style>$css</style>"); $pdf->write("<div class='hello'>hello</div>"); $pdf->write("<div class='world'>world</div>"); d($pdf->save()); This is the result of $pdf->html() <style> .border { border: 1pt solid #afafaf; } .hello { border: 1pt solid #afafaf; color: blue; padding-top: 10pt; } .world { border: 1pt solid #afafaf; color: red; padding-top: 20pt; } </style> <div class='hello'>hello</div> <div class='world'>world</div>
-
Thx - haha, I did now see that you have a screenshot in the first post. Didn't realize that as it's a bit small and pixelated ?
-
Hi @Jan Romero so is this module still usable? Do you have any links where the module is in action?
-
Thx @adrian the strange thing is. If the load order of the modules was the problem, shouldn't the bd() throw an error that the function does not exist? The hook seems to be fired, because the $this->message() shows up. ?
-
Today one of my dearest customers "Claudine" has her 50th birthday!! ?? She works a lot with their PW-based Software and I thought it would be nice to show her a birthday popup on the next login: RockBirthday ProcessWire module to show a happy birthday message within a given period after birthday. Usage Just install the module and customize it via hooks in /site/init.php (not ready.php!) // dont show message after set maxDays $wire->addHookAfter("RockBirthday::setConfig", function($event) { $event->object->maxDays = 30; // 14 is default }); // get date of birth of user // must return a timestamp (int) $wire->addHookAfter("RockBirthday::getBirthdate", function($event) { $user = $this->user; $event->return = $user->getUnformatted('your_birthdate_field'); }); // get markup of message $wire->addHookAfter("RockBirthday::getMarkup", function($event) { $user = $this->user; $html = "<h1>Happy Birthday, {$user->name}!</h1>"; $event->return = "<script>vex.open({unsafeContent: \"$html\"});</script>"; }); https://modules.processwire.com/modules/rock-birthday/ https://github.com/BernhardBaumrock/RockBirthday
-
- 6
-
-
-
Hi @adrian today Tracy cost me 1 hour of work ? $this->addHookAfter('Session::loginSuccess', function(HookEvent $event) { bd('Session::loginSuccess'); }); No matter what hook I tried (Session::login, ProcessLogin::loginSuccess etc) tracy did not dump anything. It seemed that the hook did never fire. I even placed a bd('Session.php') in Session.php... nothing! ? I tried different Session Handlers (DB, default), tried hooking ::logout (which worked) etc etc. Then I found: $this->addHookAfter('Session::loginSuccess', function(HookEvent $event) { bd('Session::loginSuccess'); $this->message('Session::loginSuccess'); }); So the hook fires, but the BD() call get's lost somewhere! The dumps recorder is also empty (not shown in the screenshot)! Any ideas what could be going on? PS: My new balance Tracy time costs: 1h Tracy time savings: 500h+ (thx once more!! ? )
-
Hey @ryan just posted a fix for an error that makes the new Image Fieldtype unusable with german locale setting due to an SQL error after image upload: https://github.com/processwire/processwire-issues/issues/1155
-
VARCHAR was a good idea adrian, thx! It tries to save 1,33 and not 1.33 So it seems to be related to locale settings. That explains why my superuser works (EN) while the other user does not (DE). Any ideas how that could be fixed and where (is this related to fieldtype code or is it a DB setting)? I guess it is related to PW because the user settings should not have any effect on the db?
-
Thx @adrian this is indeed related. Totally forgot about that. But still, it does neither solve the problem (because saving the ratio as INT is at the moment not possible) nor does it explain anything (for me). I thought that maybe saving the ratio as INT (1.33 = 133) might be better, but I guess that would also just be a hack, because saving 1.33 into a database cell should really not be a problem. I'm not that deep into databases... maybe @LostKobrakai @Robin S or @BitPoet have an idea?
-
Hi @kongondo thx for jumping in ? Yes, I checked that. Sorry if I was unclear. That's exactly the case. It works for superusers but it does not work for regular site editors. First I thought this was related to my repeater-setup. But I checked with a single image field on the home template and got the same result. I have no idea how that can happen and why the value of ratio would be related to the users role. Different behaviour across different db systems is reasonable for me, but not across different pw roles ? Also, I don't understand why it does not accept a hardcoded value of 1.33 as decimal(4,2) for ratio?
-
I get this error with the new Image field when trying to upload an image as non-superuser on LINUX + MariaDB 10.2.31 (local dev setup on win + mysql works). Has anybody experienced something similar or can help me fix this issue? I narrowed it down to line 141 of FieldtypeImage: https://github.com/processwire/processwire/blob/dde4c92b784b3d89ef36fa3a731081b10e50422d/wire/modules/Fieldtype/FieldtypeImage.module#L141 When I hardcode the ratio to 1 everything works. When I dump the value via Tracy it says a ratio of 1.33; Hardcoding 1.33 does show the same error. Any ideas?
-
Sorry - didn't get that you are talking about Fieldtype/Inputfield modules! They are definitely not that easy to grasp! ? It also took me really long to understand how they work and what the important parts are... The problem is that it's quite easy once you know how things work, but it's quite hard to understand what's going on when and where when you look at the code of a finished module (like the events fieldtype that was intended to be a tutorial module...). Having said that, I'm still not sure if you really need a fieldtype/inputfield module. Also a basic module comes with the benefits mentioned above and it's as simple as that: class YourModule extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'YourModule', 'version' => '0.0.1', 'summary' => 'Your module description', ]; } function evaluate_condition($condition, $pageId) { // your code here } } Then you can call your function: $modules->get('YourModule')->evaluate_condition('foo', 123); That's very little effort for lots of benefits. Maybe you don't even need to create a full blown Inputfield/Fieldtype module. You could maybe just make it autoload and add a hook to your module: class YourModule extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'YourModule', 'version' => '0.0.1', 'summary' => 'Your module description', 'autoload' => true, // added this ]; } public function init() { $this->addHookAfter("Inputfield::render", function($event) { $event->return .= "<div>My modified Inputfield</div>"; }); } function evaluate_condition($condition, $pageId) { // your code here } } Or even better, since you always check the condition for a single page, attach the method to the page object: class YourModule extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'YourModule', 'version' => '0.0.1', 'summary' => 'Your module description', 'autoload' => true, ]; } public function init() { $this->addHookAfter("Page::evaluate_condition", $this, "evaluate_condition"); } function evaluate_condition(HookEvent $event) { $page = $event->object; $condition = $event->arguments(0); // your code here // instead of return 'foo' use $event->return = 'foo' } } Then you can do this on any processwire $page $page->evaluate_condition("foo"); PS: The boilerplate code for every module is always the same. It might look frightening at first sight, but using vscode snippets for example it's really just typing "pwmodule" and filling in the placeholders (like shown in the gif above). https://marketplace.visualstudio.com/items?itemName=baumrock.pwsnippets
-
IMHO it's almost always worth building a module: You can share it across projects You can fix bux and add features in a central place You can easily share it with the community You can add documentation easily via readme file And it's really almost no extra effort:
-
v0.0.5 adds the link to the used parser to the readme and a parse() method to parse a string of less (not a less file)
-
The fix for toggling inputfields caused ajax fields to close right after they were opened. v0.0.7 fixes that ?
-
Not sure if that would help, but I'm curious: Have you ever tried RockFinder2 ? ? +1 for custom db tables and custom SQL. RockFinder2 makes combining custom SQL + PW magic (like access control, hidden/published pages, pagination etc) really easy!
-
Hi Jay, you can find the source code here: https://gitlab.com/baumrock/geowire But I have to say that I was not able to install it on my dev laptop any more. I'd have to have a look on my old machine if there is a working version left. Maybe you can get it up and running though. But in general I'd not recommend using it any more. It was my first project and has some concepts that I'd definitely not use any more (like placing files in the root folder). I had no idea about hooks or modules at that time. Maybe some parts are interesting nevertheless ?
-
+1 I have automatic backups every hour during development and do manual backups when reaching milestones and they get deleted from time to time so I need to manually restore them. In my case it would be enough to exclude special filenames from deleting.