ProcessWire 3.0.153 core updates

Version 3.0.153 of the core on the dev branch focuses on comments field updates, significant refactoring/improvements to ProcessWire’s core Template class and PagesLoader class (which is used by the $pages API variable).

New $pages API method

The $pages API variable also gains a new method this week:

$pages->has('selector'); 

This method provides an optimal way to check if any page matching the given selector exists in the system. It can do this with more efficiency than $pages->get(); because it doesn’t have to load any Page, and with more efficiency than $pages->count(); because it doesn’t have to count a total number of matches. However, rather than just returning a true or false, it returns the ID of the first matching page, which adds additional potential use cases.

Previously I had been using $pages->get() or $pages->count() whenever I needed to quickly check for the existence of something. Both are quite fast. But in many cases I didn’t need the loaded Page (object), or the total count, and instead just needed to know if something existed. I’m sure others have had the same need as well. So I thought ProcessWire should have a way of providing this without the overhead of loading a Page or counting a total quantity of pages — the new $pages->has() method does just that! This method will accept the same $selector argument as any $pages->get(), $pages->find() or $pages->count() method.

In addition to this new method, there was a lot of refactoring and optimization in the PagesLoader class, which is used by the $pages API variable. The updates were significant enough that they belong where they are — on the dev branch — so be sure to let me know if you observe any new issues introduced as a result of the refactoring.

Template updates

The Template class got a significant refactoring that makes code improvements and optimizations to existing methods. In the process, it also gained a few new methods. Most will likely never need or use these, but I did (and a few of you might too), it's good for the core, and it's what I worked on, so I'll mention them anyway. 😀

$template->allowNewPages();

Returns an up or down (true or false) as to whether or not new pages are allowed to be created with the given template. It’s basically a simpler interface to the $template->noParents property.

$template->childTemplates();

This is like the $template->childTemplates property, except that it returns a WireArray of Template object rather than the IDs (integers) of templates allowed for templates used by child pages.

$template->parentTemplates();

This is like the $template->parentTemplates property, except that it returns a WireArray of Template objects rather than the IDs (integers) of templates that are allowed for templates used by parent pages.

Either of the methods above can also be used for setting the value when given an argument.

Comments field updates

Finally, the Comments field received major API improvements (also mentioned in last week’s forum post), making the comments field able to better handle completely custom markup for both comments and the forms to submit them. A couple new classes were added (CommentListCustom and CommentFormCustom), and existing classes went through major refactoring. There were some major API additions as well, but none that caused any breaking changes to the existing API, so it should all keep working as it always has.

Both CommentsListCustom and CommentsFormCustom include usage examples at the top of the class files (click the links to see). Use these when you need more control than what the existing comments output provides. Though if you are fine with the existing markup produced by the comments field then using the Custom classes isn’t necessary. But when the need does arise to do something really custom with comments, I think you'll be pleased with what these updates and additions provide.

That’s all for this week. This post is a bit short and updates are a bit technical, I know; thank you for reading anyway. I like to focus on code and details, especially when needing a distraction from the news, as I'm sure we all do. I'm currently adjusting to a new way of working, with everyone home 24/7 for safety; though that part (wife and kids around) is nice, even if it slows work a bit. I hope you and your families are all staying healthy and safe. Have a good weekend and enjoy reading the latest issue of ProcessWire Weekly.

 

PrevProcessWire 3.0.152 core updates

6

This week we have some major improvements to our core date/time Inputfield, as well as a new ability to specify your own custom classes for Page objects. Read on for all the details and examples.  More 

NextProcessWire updates and additions in progress

3

This week we’ve got a few new and interesting core updates in progress, though none quite ready to release just yet. So rather than releasing version 3.0.154 today, I thought we'd instead take a brief look at what’s coming over the next few weeks. This post covers all the details. More 

Twitter updates

  • This week a 2nd new module for processing Stripe payments has been added to FormBuilder. Unlike our other Stripe Inputfield, this new one supports 3D Secure (SCA) payments. We’ll take a closer look at it in this post, plus a live demo— More
    16 October 2020
  • Quick weekly update covering this week's commits for the upcoming 3.0.167 ProcessWire core version— More
    18 September 2020
  • This week ProcessWire version 3.0.166 is released on the dev branch. In this post we’ll cover all that’s new relative to the previous version, 3.0.165. Plus we’ll check out the latest new versions of ProCache and FormBuilder— More
    11 September 2020

Latest news

  • ProcessWire Weekly #337
    In the 337th issue of ProcessWire Weekly we're going to introduce a couple of brand new third party modules, take a closer look at the latest core updates, and more. Read on!
    Weekly.pw / 24 October 2020
  • Stripe Payment Processor for FormBuilder
    This week a second new module for processing Stripe payments has been added to FormBuilder. We’ll take a closer look at it in this blog post, plus we’ve got a demo of it here too.
    Blog / 16 October 2020
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK