Jump to content

Jonathan Lahijani

Members
  • Posts

    769
  • Joined

  • Last visited

  • Days Won

    35

Everything posted by Jonathan Lahijani

  1. It's nice to see a ProcessWire site that's close to home!
  2. I asked ChatGPT and it gave me what I needed to know: Therefore, I've moved the relevant hooks into a method outside of ready() and am attaching the hooks explicitly now in my script.
  3. I have a module that I created which I am installing and then running a method on via the command line (although this issue still occurs when running in the script in my browser as well). My script looks like this (I've heavily simplified it here to demonstrate the issue precisely): <?php namespace ProcessWire; include(dirname(__FILE__).'/../index.php'); // bootstrap processwire wire('modules')->install('MyModule'); wire('modules')->get('MyModule')->setupDemo(); MyModule's ready() method contains various hooks, many of which do things on page save. MyModule's setupDemo() method does a bunch of stuff like creating pages and fields. The problem is, when doing those two things back-to-back as shown above, the ready() method doesn't get executed for some reason and therefore the hooks do not get applied! As a result, the various things that rely on hooks in setupDemo() do not execute. If I were to split the two method calls into two different scripts and ran them one after another, this issue does not occur. What am I doing wrong? I've tried wire('modules')->refresh(); between the two calls and several other things but no luck. Note: if I call the ready() method explicitly, it causes problems as well.
  4. I had my own similar moment today. I was using the API to install a Fieldtype module, such as FieldtypeToggle. It was not working and after an hour of debugging, I found out I had capitalized the T in Fieldtype (FieldTypeToggle -- bad!) which ProcessWire doesn't play nicely with.
  5. The problem I had was with the way I was using the head-support extension. I was using the "merge" behavior instead of the "append" behavior. Merging would destroy all Tracy injected code that it placed in <head>, but appending preserves it. Appending leaves a bit of extra HTML behind after HTMX does its merge, but it doesn't affect how a page gets rendered or lead to incorrect results.
  6. An update on this as I now know what the problem is... If using TracyDebugger with HTMX's head-support extension, TracyDebugger's bar will become "unstyled" when doing an htmx-style request. This happens because the CSS that TracyDebugger uses to style the bar gets stripped-out with that extension (since it's in the <head> and the two don't play nicely with each other). I will follow up with a solution if I'm able to find one.
  7. I find myself continuously running various commands that interface with ProcessWire while developing a site. For example, I may want to delete all the orders in the ecommerce site I'm currently developing. My approach for a while has been to have a bunch of 1-off PHP scripts that I'd run (either via command line or through a link since it's publicly accessible), but I was wondering if there's a more formal way to do this with ProcessWire. Laravel has Artisan, Craft CMS has Console Commands for example. I think wire shell (wtf the forum software keeps breaking this word up) solved this but it's abandoned (sadly). Any recommendations?
  8. I'm going to staple this to my head!
  9. @bernhard My current strategy for detecting development/staging/production environment is currently based on using gethostname() or server_name, depending on the site and setting a custom $config->env variable. Eventually I will switch to a cleaner way when Ryan hopefully officially implements something more formal. I saw your PR and have read the various discussions on this topic. That aside, I would still want guestForceDevelopmentLocal to apply specifically to myself (based on IP or some other method) because sometimes I let people view my local dev environment from the outside and I don't want them to see the debug bar.
  10. GPT has really helped me with bash scripts and writing regular expressions, two very cryptic things that it handles extremely well. Love it.
  11. How would I halt output of a template file using return $this->halt(); but with that code not actually appearing in the template file itself? In short, I want to halt output of a template file at some point using the halt method described, but I want to have it be done more flexibly, meaning I want that code to exist within my ready.php for example (or just somewhere not in the template file). What's the best way to do this? I don't want to use exit because it has unintended consequences.
  12. @adrian Based on my approach above, which I'd like to keep, I additionally also want to enable TD development mode if I'm a guest and it matches my specific IP address. Is that possible? The way the allowedTracyUser method is written seems to suggest it is not.
  13. That's correct. I oftentimes have non-developers set as the Superuser role, but I wouldn't want them to see the Tracy Debugger bar. Edit: I should reword my explanation as my usage of Development and Production is confusing within the context of Tracy Debugger.
  14. I wanted to share the way I enable Tracy Debugger for myself (a superuser) and myself only, only when logged in. This is useful if there are other superusers that are not developers and you don't want them to see the Tracy Debugger bar. There's a variety of settings and methods related to this, but I wanted to distill it into a few short steps: create a permission called 'tracy-debugger' (note: Tracy Debugger doesn't create this permission for you during installation) create a role called 'developer' (sounds like the right name to me) assuming you're a superuser, edit your account and assign the 'developer' role; if there are multiple developers on the project, consider assigning them this role as well in Tracy Debugger's settings do the following: Main Setup → Output Mode → DEVELOPMENT Access Permission → Restrict Superusers → checked
  15. I'm putting this here in case anyone finds this useful (or I google this myself in a few years)... Let's say you have the following in config.php: // config.php $config->myArray = [ 'foo' => [ 'k1' => 'v1', 'k2' => 'v2' ], 'bar' => 'some string', 'baz' => ['some', 'other', 'array'] ]; Now you want to want to add an item to the 'foo' array somewhere else in your codebase (template file, a module's init method, etc.). This won't work (overloaded notice will occur): $config->myArray['foo']['k3'] = 'v3'; Correct way to do it: $config->myArray = array_merge( $config->myArray, [ 'foo' => // existing $config->myArray['foo'] + // new [ 'k3' => 'v3' ] ] );
  16. Is this happening on other PW installations on the same machine and separate/similar DDEV environment? Did you check apache error logs for anything suspicious?
  17. There's no way to halt a template rendering from within my custom module's ready method? return $this->halt(); doesn't work ?
  18. This is an excellent idea and would simplify some of the gymnastics required when working with HTMX or similar libraries. I think this would fit nicely into how ProcessWire works.
  19. How would I get a list of uninstalled/installable modules (or all modules whether installed or uninstalled)?
  20. I have a URL hook like this which acts as an API endpoint: wire()->addHook('/foo/', function(HookEvent $event) { bd($event); }); That endpoint will be hit from somewhere with some post data, outside of ProcessWire. As you can see, I have a bardump to log $event, but I won't be able to see that output because it's coming from some outside request. How do I actually log it and store it (without using ProcessWire's own $log capabilities)?
  21. I'm developing a very advanced ecommerce site with ProcessWire and an order needs to have various related pieces of data. To keep it simple for this example, an order should log payment attempts ('payment' template) and the items that were fulfilled ('fulfillment' template). Let's assume our order is here in the page tree, where 123 represents a page using the 'order' template (which contains the billing address and things like that): /orders/123/ One scenario that I often come across when developing ProcessWire sites with strong data relationships is where to put related pieces of data. In the situation I described, I could do it in one of three ways: Approach 1: as child pages of 'order' template I could make payments and fulfillments as children of the 'order' template. This is a ProcessWire-y way to do it. Approach 2: under one separate master page I could make payments and fulfillments as children of /order-updates/ and establish the relationship using an 'order' page reference field on the 'payment' and 'fulfillment' templates. This is a blend between traditional database design and a ProcessWire-y way to do it. Approach 3: under multiple master pages I could make payments as children of /payments/ and fulfillments as children of /fulfillments/ and establish the relationship using an 'order' page reference field on the 'payment' and 'fulfillment' templates. This is a traditional database design way to do it. What are your thoughts in regards to this specific example? Do any of them have pitfalls that I don't foresee? If I had to switch from one technique to another, that would be easy to do with a simple migration script.
  22. I oftentimes create a checkbox field called 'test' and assign it to certain templates. I check the box if the page is a test page. These pages may exist on the live site and I don't want to hide or unpublish them, but at the same time, I don't want them to appear in the XML Sitemap. (not part of this tutorial, but I also noindex,nofollow those pages using a meta tag in the head so search engines don't index them) In that case, you can remove them from the WireSitemapXML like this in /site/ready.php: $wire->addHookAfter('WireSitemapXML::allowPage', function(HookEvent $event) { $page = $event->arguments('page'); if($page->hasField('test') && $page->test) $event->return = false; });
  23. If accessibility and avoiding lawsuits matters, I'd avoid going that route. I spoke with a developer friend recently whose client got hit with an accessibility lawsuit. They then had a special accessibility firm audit and maintain the website. Sometime afterwards they got hit with 2 more accessibility lawsuits, although they were thrown out. This might be mainly a US phenomenon however... gotta keep those lawyers busy! UIkit pushed a big update today that (finally) addresses a lot of accessibility issues.
  24. Thanks. To get the width and height of an image, I'm doing this: // within repeater loop that has a file field called 'project_file' $imageSizer = new ImageSizer($project_file->filename); $width = $imageSizer->getWidth(); $height = $imageSizer->getHeight();
  25. I have a field that uses the Files fieldtype. Images and videos are being uploaded to it. Because it is not an Image fieldtype, I can't get an image width or height. I believe there is a way with the Pageimages class, but I'm a bit rusty on how to do this. There was a post on here that discussed how to do it but I can't find it. Any help would be appreciated.
×
×
  • Create New...