Vigilante Posted December 23, 2017 Share Posted December 23, 2017 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. Link to comment Share on other sites More sharing options...
incognito.ms Posted December 23, 2017 Share Posted December 23, 2017 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/ 3 Link to comment Share on other sites More sharing options...
dragan Posted December 23, 2017 Share Posted December 23, 2017 And then, there's always array_unique() or http://cheatsheet.processwire.com/pagearray-wirearray/getting-items/a-unique/ Link to comment Share on other sites More sharing options...
Vigilante Posted December 23, 2017 Author Share Posted December 23, 2017 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? Link to comment Share on other sites More sharing options...
dragan Posted December 23, 2017 Share Posted December 23, 2017 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/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now