hellomoto Posted September 6, 2015 Share Posted September 6, 2015 When creating a new "track" page "uploader" users are supposed to choose a parent page but none show up in the select field. So I included in an autoload module, this: public function init() { $this->pages->addHookBefore('ProcessPageAdd::execute', $this, 'hookAssignTrack'); } public function hookAssignTrack(HookEvent $event) { if ($this->input->get->template_id == 43) { echo "{$this->page->parent->name} | "; $username = wire("user")->get("name"); $profile = wire("pages")->get("/users/{$username}"); $p = new Page(); $p->template = "track"; $p->parent = $profile; $p->save(); //(int) $del = $p->id - 1; //wire("pages")->get($del)->delete(); $goTo = wire('config')->urls->admin . "page/edit/?id={$p->id}"; wire("session")->redirect($goTo); } } However the page that is created and saved here always comes with one preceding it (if the successfully saved new page's ID is 1012 there's also a blank 1011). Hence the commented out attempt to just delete the other one, but that ends up not only not creating an empty page but also deleting the last good one. Why is this, how can I fix it? Edit: I changed the Add New link to {$config->urls->admin}page/add/?parent_id={$profile->id} and removed the above hook but it's still creating the extra empty page right before it. They open in a modal, and even if I just exit the modal and don't enter anything or save anything, I guess since it's already been created under the parent and unpublished pages aren't allowed, two new pages are still created, empty.. 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