Jump to content

MoritzLost

Members
  • Content Count

    318
  • Joined

  • Last visited

  • Days Won

    16

MoritzLost last won the day on April 14

MoritzLost had the most liked content!

Community Reputation

847 Excellent

2 Followers

About MoritzLost

  • Rank
    Sr. Member

Contact Methods

  • Website URL
    https://moritzlost.de

Profile Information

  • Gender
    Male
  • Location
    Cologne, Germany

Recent Profile Visitors

1,518 profile views
  1. You have a couple of options: You can create the required fields (and templates, if any) programmatically in the install() method of your module (see the documentation). Creating fields through the API is pretty straightforward, though you might have to dig a bit to find the properties you need if you want to customize the field's settings. In this case, you should probably also handle removing those fields in the uninstall() method so your module can be uninstalled cleanly (make sure to warn the user that uninstalling the module will remove all of it's data in this case!). The benefit o
  2. You're confusing variable type and object classes. gettype() returns the type of a variable, i.e. string, int, object etc. If you want to know the class, use get_class(). Note that this will return the fully qualified classname, i.e. ProcessWire\PageArray. If you want to get the classname without the namespace, you can also use Wire::className, which is a method available on all classes extending the Wire class (so pretty much all ProcessWire classes). This one gives you only the classname with the namespace by default: $somePageArray->className(); // PageArray
  3. @3fingers No that's actually correct, I'm checking the class of the formatted values there, not the class of the fieldtype. For example, for an image field, the $value will be an instance of Pageimage or Pageimages depending on the formatting settings, but the $type will be an instance of InputfieldImage. In fact, the $type variable is not needed at all. In the first version I started by checking the $type, but turned out checking the $value directly was more efficient. Though you could do it both ways. That would only work if you're working with field objects, not formatted values. Th
  4. @Hector Nguyen Functions can't be autoloaded in PHP. Two options to work around this: Put the QFramework\Function function in a class as a static method, then the class can be autoloaded. Add all files containing functions in the autoload files list in your composer.json. This way those files will be included on every request.
  5. @AndZyk Alright, I had some fun with it. Here's an improved script for the asset export, which can handle nested repeater and matrix repeater fields: /** * Get a flat array of all images on the given page, even in nested repeater / repeater matrix fields. * * @var Page $page The page to get the images from. * @return Pageimage[] Array of Pageimage objects. */ function getImages(Page $page): WireArray { $images = new WireArray(); $fields = $page->fields->each('name'); foreach ($fields as $field) { $value = $page->get($field); $type = $page->fields->{$field}
  6. What do you want to achieve? Do you want to get all images for a project out of the system to use them externally? Or do you want to restructure how/where ProcessWire saves images in general? For the first case, you can write a little script to iterate recursively through all fields, including any repeater / repeater matrix sub-fields, to get an array of images. Then you can use that to copy all the images to one folder (using $files->copy(), for example), get a link of filenames (see Pagefile::filename()) or do whatever you want with them, like export their meta data as JSON or anythi
  7. Don't overthink it. You're gonna need a way to reference a specific field anyway. Hiding the name away behind a constant, config or whatever isn't going to change that. If you're worried about changing field names, you should instead invest the time to find better names for your fields. Why would your field names change? Probably because the data they hold or the thing they represent have changed - both of those cases will require adjustments in the templates anyway. I've never understood the benefit of "hiding" a property or method name behind a constant. I mean, what are you gonna do if
  8. @adrian Awesome, thanks for the fix adrian, you're my hero 🤩 Didn't know about the OPT + Enter shortcut, that's handy indeed! I removed the snippet through the Console panel, that bit worked fine, I guess the problem was just the shortcut trying to load a snippet after it had been deleted. Anyway, thanks again!
  9. Hi @adrian, I'm having a small but annoying issue with the Console panel in the debug bar. I'm using the Console to quickly try out code snippets, so most of the time I enter some code and hit CMD + Enter to run it. I've rarely ever used the option to save snippets on the right side. Now I tried to save a snippet which somehow broke the CMD + Enter shortcut. After saving a snippet, hitting CMD + Enter always wipes out whatever I have entered in the code input and restore that snippet from disk, instead of running the code I entered in the code input. Clicking the "Run" button above the code wi
  10. Quick tip: Displaying hCaptcha in the correct language By default, hCaptcha displays its interface in the visitor's browser language, which means it may differ from the current language of your site. You might want to change that to always use your site's language, or the current language if you have a multi-language site. You can use the hook InputfieldHCaptcha::getScriptOptions to adjust the language of the hCaptcha interface dynamically. Here's a snippet with a couple of options for setting the language: // site/ready.php wire()->addHookAfter('InputfieldHCaptcha::getScriptOptio
  11. Thanks @adrian! Sorry I forgot to mention the versions ^^ The site I ran into this problem is still on PHP 7.4, but the update fixed the problem nonetheless. Thanks for the quick response!
  12. ProcessCacheControl version 1.1.0 released I just released an updated version of this module which fixes some issues with the asset version management feature. In particular: When using CacheControlTools::getAssetVersion while no asset version existed (for the specified category), the implicitly generated version incorrectly expired after one day. This is now fixed, so asset versions will not expirate anymore until manually cleared. Asset versions are no stored using WireCache::expireNever instead of WireCache::expireReserved. This means they will be deleted when using $cache-
  13. Hi @adrian, I've got another small issue between TracyDebugger and one of my modules. Not sure if the problem is Tracy, my module or the core, anyway ... The problem is my ProcessCacheControl module, which comes with two module files: ProcessCacheControl itself, which is a Process module, and the helper module CacheControlTools, which implements the Module interface but extends Wire (instead of WireData). When dumping an instance of the CacheControlTools module, I get a fatal exception: Steps to reproduce: Install ProcessCacheControl In the console or any template, try
  14. @fruid I'd still test your mail with the mail-tester tool mentioned above to make sure your email doesn't appear "spammy". Depending on your settings and whether you're sending through the mail server of your hosting your mail may appear to be unauthenticated. Anyway, it's curious that WireMailSmtp isn't working but WireMailPHPMailer is, are you using the same settings for both? By the way, I'd be slightly wary when the provider tells you to use port 587. In general, TLS-encrypted mail should use port 465. Port 587 is for STARTTLS, which starts SSL-encryption only after a connection has b
  15. Yes, that's correct. The default value is only used for the interface, it's not applied to any existing pages. You can fix that in two ways: 1. Anywhere you use the value in your code, assume the default if no value is set. Something like this: // default to behavior option one $behaviorField = $fields->get('speciality_text_behavior'); $textBehavior = $page->speciality_text_behavior->id ?: $behaviorField->type->getOptions($behaviorField)->get('id=1')->id; You could also put that in a hook to get that behaviour anywhere you use this field. 2. Write a script
×
×
  • Create New...