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 we’re proud to announce the newest ProcessWire master version 3.0.164. Relative to the previous master (3.0.148) this version adds a ton of new & useful features and fixes more than 85 issues, with more than 225 commits over 7 months— More
    7 August 2020
  • ProcessWire 3.0.163 resolves more than a dozen issue reports and adds new hooks and configurable module install options, among numerous other updates. In addition, a major update to ProCache (v4.0) has been released— More
    24 July 2020
  • Weekly update for 17 July 2020 and a look at new features coming in next week's version of ProCache— More
    17 July 2020

Latest news

  • ProcessWire Weekly #325
    In the 325th issue of ProcessWire Weekly we're going to cover a new master version of ProcessWire, introduce the Textformatter Audio Embed module, and more. Read on!
    Weekly.pw / 1 August 2020
  • ProcessWire 3.0.164 new master version
    This week we’re proud to announce the newest ProcessWire master version 3.0.164. Relative to the previous master version (3.0.148) this version adds a ton of new and useful features and fixes more than 85 issues, with more than 225 commits over a period of 7 months.
    Blog / 7 August 2020
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer