Pete Posted May 19, 2012 Share Posted May 19, 2012 Got it When creating a page in the API its default status is published, whereas items entered into a repeater in the API seem to be unpublished and hidden. As such, you need to do the following to each item in the repeater: $pageid = [your page generated via the API that contains the repeater] - must be saved before adding the repeater items in order to get the page ID $repeaterpage = wire('pages')->get($pageid)->repeater_field->first(); $repeaterpage->removeStatus(Page::statusUnpublished); $repeaterpage->removeStatus(Page::statusHidden); $repeaterpage->save(); The code above only does it for the first item, but for my needs each repeater is only being imported with a single item for now and other items will be added over time - if you had more items in the repeater you would need to iterate through them of course. Just needed some sleep and a morning coffee for this one I should have 600+ files imported from a third-party file management script by the end of the weekend now - just got a wedding to go to in the meantime else I'd have this all wrapped up by lunchtime I reckon 1 Link to comment Share on other sites More sharing options...
ryan Posted May 19, 2012 Author Share Posted May 19, 2012 Pete, sorry I didn't catch your message before you'd figured this out yourself. But it looks to me like you got it right. As you found, repeater pages are kept unpublished+hidden until set otherwise. This is because repeaters may keep one or more 'ready' pages, that are ready to be populated in the admin. If there weren't any ready pages, then your repeater_field->first(); would return null rather than a Page. So if your ready pages were set at 0 for that field, then you'd want to start a new repeater page like this: $field = $fields->get('repeater_field_name'); $newRepeater = $field->type->getBlankRepeaterPage($page, $field); $newRepeater->status = Page::statusOn; // same as removing unpubished+hidden // ...populate any values to repeater... $newRepeater->save(); But you don't need to do this since you appear to have one or more ready pages already being created by the repeater, so your first() method works just fine. I still need to make a simpler API to the repeater field... Link to comment Share on other sites More sharing options...
Pete Posted May 20, 2012 Share Posted May 20, 2012 No problem ryan - it was easy enough for me to work out in the end as I knew the repeater page was being created so there was only going to be one reason why it wasn't showing. $newRepeater->status = Page::statusOn; That's a bit easier - thanks! Link to comment Share on other sites More sharing options...
ryan Posted May 21, 2012 Author Share Posted May 21, 2012 It took me awhile to figure it out, but think I've finally fixed the issue that was occurring when pages with repeaters were cloned. I was wondering if anyone else that is using repeaters in a test environment would mind testing it out too? The fix is in the latest commit. To clone, you install the ProcessPageClone module (comes with PW core) and then click "copy" on any of the pages in the page tree that are using repeaters. I just want to confirm that the fix works for other people in addition to me. Thanks, Ryan Link to comment Share on other sites More sharing options...
diogo Posted May 21, 2012 Share Posted May 21, 2012 Tested before and after updating. Before updating all the repeater fields were deleted when i cloned the page. After the update it didn't happen anymore. Link to comment Share on other sites More sharing options...
ryan Posted May 21, 2012 Author Share Posted May 21, 2012 @Diogo: Thanks for testing! Just to confirm, it's working how it should? It sounds to me like it is, but let me know if any of the behavior was unexpected. @Pete: I've updated the API for adding repeater items so that it is now simpler. Lets say that you've got a repeater field called 'buildings', and you want to add a new building. Here's how you can do it now: $building = $page->buildings->addNew(); $building->title = 'Sears Tower'; $building->height = 1400; $page->save(); That addNew() method can now be called on any repeater value. If there is a ready page waiting to be populated it returns that. If not, it will create a new page right there. It will be saved when you save your main $page. This hopefully makes the repeaters API a lot simpler. 1 Link to comment Share on other sites More sharing options...
diogo Posted May 21, 2012 Share Posted May 21, 2012 I didn't test a lot. I really didn't do more than described on my post. But yes, with this limited test, It's working as it should. 1 Link to comment Share on other sites More sharing options...
Soma Posted May 21, 2012 Share Posted May 21, 2012 Just tested on my local install. Cloning nested pages with repeater now work. So far nothing get's added or deleted. Thanks Ryan! 1 Link to comment Share on other sites More sharing options...
ryan Posted May 22, 2012 Author Share Posted May 22, 2012 Thanks for testing Diogo and Soma! This was the last issue to resolve before making PW 2.2 final. Unless anything else turns up, I'll look to do a formal PW 2.2 announcement within the next 24-36 hours. I've posted the documentation for FieldtypeRepeater here: http://processwire.com/api/fieldtypes/repeaters/ Thanks, Ryan Link to comment Share on other sites More sharing options...
slkwrm Posted May 22, 2012 Share Posted May 22, 2012 Ryan, just tested it and it seems like I found a bug, though I'm not sure. Maybe it's just me doing something wrong) Cloning is working fine, but when I add new repeater item, then, for example, select image file and fill other fields, after I hit save I can't see my just added unit untill I click "Add item". I have ready-to-edit (unpublished) items set to 1. Then if I add second item, after saving I see only my second item. Haven't tested it further, don't have much time right now. Is it a bug? Can you reproduce this, guys? 1 Link to comment Share on other sites More sharing options...
Soma Posted May 22, 2012 Share Posted May 22, 2012 slkwrm, I have tried, but can't reproduce here. It always stays as it should when I hit save. Link to comment Share on other sites More sharing options...
Pete Posted May 22, 2012 Share Posted May 22, 2012 Thanks for updating the API ryan - I've imported all the necessary data already but will definitely test it on something else soon Link to comment Share on other sites More sharing options...
slkwrm Posted May 22, 2012 Share Posted May 22, 2012 Ok, this bug appears only when I choose images in repeater unit without entering images description, also fill google maps field with a city name. Can anybody confirm? Link to comment Share on other sites More sharing options...
ryan Posted May 22, 2012 Author Share Posted May 22, 2012 Thanks for finding the bug. I was able to reproduce that with a repeater having just an images field, and then dragging in an image. The reason it wasn't working is because no changes to the page were actually made when you hit save. The changes were made before that via ajax (where the image was added). As a result, InputfieldRepeater didn't know to publish the item. I have fixed this and just pushed in the latest commit. Can you confirm that it fixes it on your end too? There was a JS update as well, and I forgot to update the module version, so you may need to hit 'reload' in your browser the first time you edit the page, just to be sure the new JS loads. For the google maps field, are you talking about FieldtypeMapMarker? I wasn't sure, because there was another one made a long time ago that I think was literally called GoogleMaps. Just wanted to be sure I had the right one. Link to comment Share on other sites More sharing options...
Soma Posted May 22, 2012 Share Posted May 22, 2012 I was also able to reproduce the image part. It now works with the latest. Thanks Ryan! Haven't tested google maps. Link to comment Share on other sites More sharing options...
slkwrm Posted May 22, 2012 Share Posted May 22, 2012 Thanks, Ryan! Repeater with Images works now. Yes, it's FieldtypeMapMarker and it worked ok initially. Sorry, I just didn't express my thoughts clearly. Link to comment Share on other sites More sharing options...
arjen Posted May 23, 2012 Share Posted May 23, 2012 Thanks Ryan for making this possible and thank you all for testing. This is something I've been looking for ages. Especially the flexibility with the API. 1 Link to comment Share on other sites More sharing options...
Pete Posted May 23, 2012 Share Posted May 23, 2012 When using search on a site, it shows up the repeater pages as well - is there a way to stop this as I suspect it's not supposed to happen? Link to comment Share on other sites More sharing options...
apeisa Posted May 23, 2012 Share Posted May 23, 2012 When using search on a site, it shows up the repeater pages as well - is there a way to stop this as I suspect it's not supposed to happen? I assume they show up only for superusers or do others see them as well? Link to comment Share on other sites More sharing options...
Pete Posted May 23, 2012 Share Posted May 23, 2012 Good question - I'll log out and check it again. Link to comment Share on other sites More sharing options...
Soma Posted May 23, 2012 Share Posted May 23, 2012 Same caught me too once. It's only when logged in as supermom. Link to comment Share on other sites More sharing options...
arjen Posted May 24, 2012 Share Posted May 24, 2012 I've added a repeater to a website - unfortunately local - and the fields won't show up for guests. It works fine if I'm logged in as admin, but not for guest. $quoteList = $pages->find("employee_quote!=")->shuffle(); $quoteList = $quoteList->shift(); $employeeQuote = $quoteList->employee_quote; if ($employeeQuote) { $mainContent .= "<blockquote>{$employeeQuote}</blockquote>"; } I've looked at all the options, but I must be missing something. Any ideas? Thanks for your thoughts! Link to comment Share on other sites More sharing options...
diogo Posted May 24, 2012 Share Posted May 24, 2012 @arjen you are calling the repeater as if it was a normal field. What fields do you have inside it? Link to comment Share on other sites More sharing options...
arjen Posted May 24, 2012 Share Posted May 24, 2012 I have a repeater field called: "employee_quotes". I have a plain text field called: "employee_quote". The employee_quote lives within employee_quotes. I was thinking this might be a rights issue, because when I'm logged in it works fine. As soon as I log out it doesn't work. Is it not possible to call direct a field within a repeater? Link to comment Share on other sites More sharing options...
Soma Posted May 24, 2012 Share Posted May 24, 2012 It works fine, I'm using repeaters and haven't run into this issue. I assume it's something with the permission on templates/pages that does not find the pages for guests. $quoteList = $pages->find("employee_quote!=")->shuffle(); This is not on page but doing a find over ALL pages there is. If the pages with the repeater on it is somwhere the guest doesn't have access it won't find them. To test this you could try adding a ",include=all" to your selector. Does it change anything? 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