picarica Posted September 27, 2021 Share Posted September 27, 2021 Hello so i am working on a hook and this hook should include setup, 1. have one or multiple zip files in one file field, Run 1. let hook unzip each file and input the unziped files into newly created page the problem, i wanted to use $files->tempDir() method in hook but i guess it't not hookalbe so i get error Undefined variable: files in at line $page->title = $files->tempDir(); i did this as test and it doesnt work, i whole setup looks like this $this->addHookAfter('Pages::saveReady', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // An 'after' hook can retrieve and/or modify the return value $return = $event->return; // Get values of arguments sent to hook (if needed) $page = $event->arguments(0); if(empty($page->id)) return; if($page->template == "generator") { foreach($page->multi_gen as $gen){ wireUnzipFile($gen->url, "my-file/"); if($this->pages->get("parent={$page->name}, name={$gen->basename}")->id) continue; $np = new Page(); $np->of(false); $np->template = $this->templates->get("hry_home"); // I changed the template name here too //$np->title = $tatel; $np->name = $np->title; // I wanted the page name to match the title $np->parent = $page; $np->save(); //$np->image->add($image->filename); //$np->image->last()->description = $image->description; //$np->save(); //// These lines work to remove the image from the parent page ////$page->images->remove($image); $page->save(); } } $event->return = $return; }); and i still haven passed the frist line containint wireunzipfile, is there any other way to do this? i ran out of ideas, now i know of that i can check in a file field that automaticaly unzipes files, the problem will be that when there will be alot of zip files, its gonna be confusing nad it will be harder to move exact files to the newly created page 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