Jump to content
Vigilante

Can a PageArray hold duplicate values?

Recommended Posts

Simple question. When I have a pagearray object and use methods like import, prepend, append, push, does PW automatically avoid duplicates? Or is it possible for a pagearray to hold multiple references to the same page?

I'm mainly concerned about import because I'm importing a multi-page reference field and don't want duplicate references if a page already exists in the pagearray.

Based on early tests/uses, it doesn't appear to have duplicate references, but I want the official answer about it.

 

And while on the subject, is there a difference between append and push? Both are described as adding a page to the end of the array, so not sure.

Share this post


Link to post
Share on other sites
22 minutes ago, Vigilante said:

Simple question. When I have a pagearray object and use methods like import, prepend, append, push, does PW automatically avoid duplicates? Or is it possible for a pagearray to hold multiple references to the same page?

I'm mainly concerned about import because I'm importing a multi-page reference field and don't want duplicate references if a page already exists in the pagearray.

Based on early tests/uses, it doesn't appear to have duplicate references, but I want the official answer about it.

import() skips over any items already present in the WireArray: https://processwire.com/api/ref/wire-array/import/

22 minutes ago, Vigilante said:

And while on the subject, is there a difference between append and push? Both are described as adding a page to the end of the array, so not sure.

Push is an alias for append: https://processwire.com/api/ref/wire-array/push/

  • Like 3

Share this post


Link to post
Share on other sites

I don't know how I missed the docs on those. I'm pretty good about searching docs first but didn't see those pages for some reason.

Processwire has good docs but I feel like there are too many different types of docs. One gives a summary, one goes a little more in depth, one is a cheatsheet. I don't know, sometimes I think I've found the doc on a thing, but it's the wrong one and some other doc has better information.

What are the best doc sources to bookmark?

Share this post


Link to post
Share on other sites

http://processwire.com/api/

Some stuff, like newer additions in v.3.x, are explained in the blog posts, and are sometimes not yet in the docs.

In some cases, like PageArray and WireArray, the more comprehensive documentation is in the Wire chapter, e.g. http://processwire.com/api/ref/wire-array/. But then there shold be a note at the top, like here: http://processwire.com/api/ref/page-array/

Quote

Please see the WireArray and PaginatedArray types for available methods, as they are not repeated here, except where PageArray has modified or extended those types in some manner. The PageArray type is functionally identical to WireArray and PaginatedArray except that it is focused specifically on managing Page objects.

There's also https://processwire-recipes.com/

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...