-
Posts
7,529 -
Joined
-
Last visited
-
Days Won
160
Everything posted by kongondo
-
Something funky going on there. I have tested the code and it definitely works. Any errors? Does a visual check reveal anything? e.g. is that child page there? Is the repeater page there? Does it work outside a module context? Do you have Tracy/Debug on? Edit Also...did you take note of my code changes?
-
My bad...The child page has to be deleted first: $page = $this->wire('pages')->get(1234); $pages = $this->wire('pages'); $repeaterID = $this->wire('fields')->get('eventpricerepeater')->id; // this is the 'repeater_field_name' page $repeaterPage = $pages->get("parent.name=repeaters, name=for-field-$repeaterID"); foreach ($page->children("include=all") as $child) { $id = $child->id; // first delete the child page $child->delete(); // this is the 'name_of_page_with_repeater' $childRepeaterPage = $repeaterPage->child("name=for-page-$id"); // will also delete the repeate item pages, e.g. the '1234567890' if($childRepeaterPage->id) $pages->delete($childRepeaterPage, true); }
-
Hi @workdreamer. Welcome to ProcessWire and the forums . You are right. Very bad practice to add/remove from the core . To override any core methods you use Hooks (as long as the method you want to override is hookable). There is an example here regarding Templates: And all about Hooks:
- 2 replies
-
- 2
-
-
- processtemplate
- module
-
(and 1 more)
Tagged with:
-
I have re-read your post and I see where we went wrong. Each field has only one repeater page. Its child pages are the parents of the repeater items. Using true in the delete deletes the repeater parent page and its children. That's what my code would do. However, you want to delete only the children. So... Repeaters Hierarchy admin Repeaters repeater_field_name name_of_page_with_repeater 1234567890// repeater item #1 on "name_of_page_with_repeater" 1346798941// repeater item #2 You want to delete 'name_of_page_with_repeater' AND NOT the page 'repeater_field_name' The below (untested) should work (@see amended code in post below...$child has to be deleted first) $page = $this->wire('pages')->get(1234); $pages = $this->wire('pages'); $repeaterID = $this->wire('fields')->get('eventpricerepeater')->id; // this is the 'repeater_field_name' page $repeaterPage = $pages->get("parent.name=repeaters, name=for-field-$repeaterID"); foreach ($page->children("include=all") as $child) { // this is the 'name_of_page_with_repeater' $childRepeaterPage = $repeaterPage->child("name=for-page-{$child->id}"); // will also delete the repeate item pages, e.g. the '1234567890' if($childRepeaterPage->id) $pages->delete($childRepeaterPage, true); $child->delete(); }
-
Repeaters pages need to be deleted a bit differently // delete repeater page: admin/repeaters/for-field-xxx $repeaterID = $fields->get('name_of_repeater_field')->id; // make sure you get the right repeater page $repeaterPage = $pages->get("parent.name=repeaters, name=for-field-$repeaterID"); if($repeaterPage->id) $pages->delete($repeaterPage, true); Regarding the error, not sure why you are getting it, but you can check like this: if($parent && $parent->id) { }
-
Alternatively render textarea as plain text
kongondo replied to heldercervantes's topic in General Support
$out = strip_tags($page->body); echo $out; strip_tags is one way to do it. I'm not sure about performance on a large body of text though. Maybe regex would be faster, I don't know -
Exactly. The more reason you should start migrating
-
Yes, it's still true today (that's PW 3.x). If you can though, I'd urge you to migrate to PDO
-
is is possible individual field setting for different template ?
kongondo replied to adrianmak's topic in General Support
Checks if you already have an image in that image field. If count returns something, it means there's an image in the field already. It presupposes you've never added more than one image before. If its empty, you can add an image, if not empty, do something else. This is near-pseudo code so things can be changed around...Edited the code above for clarity -
is is possible individual field setting for different template ?
kongondo replied to adrianmak's topic in General Support
if($page->template == 'one-image-template') { if(!count($page->multi_image_field)) { // add image, none added yet } } else { // add as many images as you like } -
This works for me $c = $page->child;// page here is the parent page //$repeaterItems = $page->repeater_test;// repeater with 6 fields (email, file, integer, text, single image, multi-images) x 2 repeater items //$c->repeater_test->import($repeaterItems);// alternative import $c->repeater_test->import($page->repeater_test);// import (into an existing repeater field in the child page) $c->of(false); $c->save('repeater_test');
-
Edit @see post below...Use import instead! (duh!, early morning!) ------------------------------------------- The process then would be: Create the child page The child page's template should have the repeater field ready to receive items Add a repeater item(s) to the child page. See this (using API to add repeater items)....getting values from the parent page Maybe there's a different way of doing this....not sure...yes...import!
-
Excluding fields in repeater when copying using API
kongondo replied to alexcapes's topic in API & Templates
More than a year later..... From the docs $building = $page->buildings->first(); // or whatever item you want to remove $page->buildings->remove($building); $page->save(); -
Or you, the module author, can click to edit the module and save (no need to make changes), and PW will fetch the latest version immediately.
-
Yeah, ta. But that means I can't use System Notifications. It reverts to the old notifications. It also means that I need to tell users of my module to have that setting off (Leave them alone) if they want to see notices in modals. Not great. Anyway, thanks guys. Currently, I am using a custom jQuery solution to show notices in modals....but still curious why System Notifications is turned off in modals
-
Benjamin, how please? I can't seem to find that setting.
-
Hmm..I wonder what the reason behind that is.
-
Yep...That was it. System Notifications notices don't show up when in a modal. The 'normal/older' notifications show up OK in a modal.
-
I need to test with the older/original PW notifications then. See below for test with the 'new' System Notifications module: Normal window notices show up OK; modal window ones do not show up at all.
-
Hmm. They've never showed up for me. What I want is for notices to show up as normal when I save, regardless of whether I am in a modal or a normal window. When I save any page in a modal (e.g. try editing a page in Batcher or a post in Blog) or when I edit and save any custom module page (e.g. some settings page in Media Manager) in a modal and call $this->message() or $this->error(), they never get shown.