-
Posts
6,314 -
Joined
-
Last visited
-
Days Won
318
Everything posted by bernhard
-
Can anybody please help me getting this chart.js work? ? https://jsfiddle.net/baumrock/f96483en/1/ It should look like this example in the docs, but I can't just copy the code of the docs over because I don't have all those util functions on my setup. Maybe someone could explain how I can make those docs examples work on my laptop as well? https://www.chartjs.org/docs/latest/samples/scales/time-max-span.html
-
This is what I came up today: <?php /** * Show warning of duplicate invoices * This will be executed on ready() of admin pages */ public function showDuplicatesWarning() { $result = $this->wire->database->query("SELECT COUNT(pages_id) AS cnt, GROUP_CONCAT(pages_id SEPARATOR '|') AS ids, `data` FROM field_yourfieldname LEFT JOIN pages ON pages.id = pages_id WHERE pages.status = 1 GROUP BY `data` HAVING cnt > 1"); foreach($result->fetchAll(\PDO::FETCH_OBJ) as $dup) { $pages = $del = ""; foreach($this->wire->pages->find("id=".$dup->ids) as $page) { $pages .= "$del<a href={$page->editUrl}>#$page</a>"; $del = ', '; } $file = $dup->data; $this->warning("Duplicate: $file found on pages $pages", Notice::allowMarkup); } } LEFT JOIN ... WHERE ... pages.status = 1 makes sure that files of pages that are in the trash are not counted ? PS: The code is part of a module and attached via hook: <?php $wire->addHookAfter("Pages::saved()", function($event) { $invoices = $this->wire->modules->get('Invoices'); $invoices->showDuplicatesWarning(); });
-
Just edit your page in the backend and then go to the tracy console and enter this: db($page); You should see a dump of your page, something like this: Then type dump($page->heroimage) and show us the results.
-
Your $page->heroimage seems to be something else than an array of pageimages... Are you using tracy? Then a bd($page->heroimage) could bring light into the dark ?
-
Custom Notes (former List of Allergens)
bernhard replied to Cybermano's topic in Module/Plugin Development
Working with PW now for several years and still have that feeling almost every day ? -
Admin - show content from a field on another page
bernhard replied to sambadave's topic in General Support
I know that a runtime field is tempting because it abstracts complexity but such things can quite easily be done via hooks as well. That means you don't need a module and you get even more possibilities: <?php $wire->addHookAfter("ProcessPageEdit::buildForm", function($event) { $page = $event->object->getPage(); if($page->template != "mytemplate") return; $form = $event->return; if($f = $form->get("title")) { $next = $page->next; if($next) $f->notes = "Title of next page: ".$next->title; } }); -
Custom Notes (former List of Allergens)
bernhard replied to Cybermano's topic in Module/Plugin Development
Congratulations for your achievements ? I think https://github.com/BitPoet/ProcessCKInlineComplete could also be a great option? Just type @... and get suggested allergens! -
Thx @WillyC this works great and one can even define multiple (non-)optional url segments ? /endpoint/{one}(/{two})?(/{three})?/
-
No ? _init.php is the file that you PREpend to the template rendering (just like _main.php is APpended). /site/init.php and /site/ready.php are something different and the place where you want to attach your hook.
-
https://snipcart.com/ can be a great option - it's as simple as it can get to setup a store (at least as long as you don't need any complicated tax/inventory/coupon/shipping/etc-stuff) and it integrates greatly with processwire, because snipcart is based all upon custom markup and that's where processwire shines. A "buy" button can be as simple as that: <button class="snipcart-add-item uk-button uk-button-primary" data-item-id="<?= $page->id ?>f" data-item-price="<?= $page->price ?>" data-item-url="<?= $page->url ?>" data-item-description="<?= $page->description ?>" data-item-image="<?= $page->image->url ?>" data-item-max-quantity="3" data-item-name="<?= $page->title ?>"> <span uk-icon="cart"></span> Buy this product </button> As you can see you can even define some basic cart logic via markup (eg max item quantity, that means the user can not add more than 3 items of this product to the cart).
-
nope, sorry, now the zeros are back in my list: That seems to happen on all hooks inside non-PW namespaced files. But not only. There are also zeros in the PW namespace. If you tell me how that works and where I have to look maybe it's easier if I try to fix it? But the code is not that easy to grasp ?
-
Yes, sorry, that's fixed. Ok it's likely one of my many modules then ? I'll have to look into it, thx!
-
I want to hook urls having this schema: /mymodule/{foo}/{bar}/{optional:urlSegment} This is what I came up with: $url = "/mymodule/(.*)/"; $this->wire->addHook($url, function(HookEvent $event) { $url = $event->arguments(1); $parts = explode("/", $url); if(count($parts) < 3 OR count($parts) > 4) { throw new Wire404Exception("Invalid number of url segments"); } ... It makes sure that I have a trailing slash and it fires on /mymodule/foo/bar/ as well as /mymodule/foo/bar/test/ Any better ideas/solutions for such "optional" url segments? PS: I have to say it again: What a brilliant feature these new url hooks!!! ?
-
Adding the namespace makes it a little more bloated but that's helpful information sometimes and therefore should not be missing, thx! ?
-
Seems the update is causing this error ?
-
@adrian thx a lot, this is a brilliant update ? I have some follow up questions: This is how my panel looks like: And this is where the hook is attached: <?php namespace GemeindeGuru; use ProcessWire\HookEvent; class Headline extends \RockMatrix\Block { public function info() { return parent::info()->setArray([ 'icon' => 'header', 'title' => 'Überschrift', 'description' => 'Fügt eine Überschrift auf der Seite ein.', ]); } public function init() { $this->addHookAfter("Pages::saveReady", $this, "saveReady"); } public function saveReady(HookEvent $event) { $page = $event->arguments(0); if($page->template !== $this->getTpl()) return; if(!$page->id) $page->title = "New Headline"; } } Any ideas why it shows 0::saveReady instead of Headline::saveReady or even better \GemeindeGuru\Headline::saveReady ? --- Another question - this line: Is this hook: $wire->addHookAfter("Pages::saveReady(template=newsitem)", function(HookEvent $event) { $page = $event->arguments(0); if(!$page->date) $page->date = $page->created; }); So I already see that anonymous functions seem to be harder to debug, so I might better use the object notation $this->addHookAfter("Foo::bar", $this, "myDescriptiveHookMethod") in the future. But in the example above, would it be hard to make tracy show "Pages::saveReady(template=newsitem)" instead of just "Pages::saveReady()" ? Not sure if that makes sense? Other opinions welcome ? --- I just clicked the saveModuleConfigData hook and landed in site\assets\cache\FileCompiler\site\modules\TracyDebugger\TracyDebugger.module.php I wonder if it was possible to link to the non-compiled version of the file? --- And last but not least: Does the order of the table give me any additional information? Like does it represent the order in which the hooks where attached? Or does it represent the order when they where fired? Or do we even see when/if the hooks where fired? If not, would that be possible? It seems that I'm getting quite long lists of hooks that are attached... not sure what to do about this, because on the one hand many of them do seem necessary (for example a saveReady hook needs to be present so that it can do its magic whenever a page is saved), on the other hand on a request where I want to debug other things that are not related to a page save at all it might be more helpful to get a list of hooks that have actually been triggered on that request. Or maybe just print them bold to be different. Hope that makes sense - thx again, I'm quite sure that this update will already save me a lot of headache in the future ?
-
Ok, got you, but that's exactly what I want in the PW backend - that's why I'm also using FA4 and not 5 ? I'm talking about module development or adding Inputfields to an InputfieldForm: $form->add([ 'type' => 'text', 'label' => 'My foo field', 'icon' => 'envelope-o', // icon without fa- prefix ]); For frontend I have a css class autocomplete plugin that also knows about all the uikit classes like uk-text-center etc:
- 242 replies
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
Why?
- 242 replies
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
Yeah no offense - it was me who posted some links about better not using flags, but just wanted to mention that I'm not so sure about that ? So it was no advice from my side - just shared the results of the quick research because I was curious ?
-
I got tired of looking up fontawesome icon codes all the time... https://marketplace.visualstudio.com/items?itemName=Janne252.fontawesome-autocomplete Using these settings: "fontAwesomeAutocomplete.patterns": ["**/*.php"], "fontAwesomeAutocomplete.insertionTemplate": {"**/*.php": "{name}"}, "fontAwesomeAutocomplete.version": "4" ?
- 242 replies
-
- 2
-
- visual studio code
- vsc
-
(and 2 more)
Tagged with:
-
I'm having all my projects under GIT and that's great. Whenever I add something to the project the files are on the live system and I can use $rm->installModule("Foo") to install that module. But when I want to REMOVE a module, that's a little different. I can delete all the files locally and push the changes to the server. The module will not be loaded any more because the files don't exist. But processwire will try to load the module and recent versions even show a warning. So I wonder if it's enough to remove the module from the modules table like this: $database->exec("DELETE FROM modules WHERE class='Foo'"); It seems to work, but I'd be happy to know if I'm missing anything here? ?
-
Not sure if it is really that bad to use flags. Especially if one also adds the name of the language as text label... I've done a little research... hetzner mollie paypal amazon I suppose they have thought about that topic ?
-
Hey @adrian I have lots of hooks firing in one project and I cant seem to find which one is causing a page name to change after save. The hooks debug panel is really helpful, but not in this case: Would it be possible to add links to that table so that if I click on "anonymous function" for example the file would open exactly at the place where this hook was added so we can inspect the code of the hook and quickly see what they are doing? edit: Ok, that was the "problem" - you might know this module ?? So my problem seems to be solved, but my request might still be helpful if it is easy to implement? ?
-
Funding ProcessWire / More community efforts
bernhard replied to pideluxe's topic in Wishlist & Roadmap
This sounds very exciting! I know someone who has already put thousands of hours into modules and techniques that could serve such a scenario very well... ? -
How to ship a module with translation files?
bernhard replied to bernhard's topic in General Support
I've created an issue in the requests repo - please give it a thumb up to show demand for such a feature! https://github.com/processwire/processwire-requests/issues/396