simonsays
Members-
Posts
74 -
Joined
-
Last visited
Everything posted by simonsays
-
@LostKobrakai Do you happen to have a good example of adding a repeater field (just the field, no data)? Found this old thread, which introduces a fairly complex approach, but it is rather old, so I was hoping, that something has changed over the last 4 years. Looked through FieldtypeRepeater module, but did not find any helpful methods.
-
Weird, failed first 2 times, but works perfectly now. Logs did not find anything. Guess, something with my localhost...
-
Subpage URLs don't work when using port number
simonsays replied to simonsays's topic in Getting Started
The problem was actually with apache virtual host (the <Directory> was not specified). Thanks for your patience and cooperation! ? -
Subpage URLs don't work when using port number
simonsays replied to simonsays's topic in Getting Started
So, what you are saying, is PW's .htaccess should work out of the box? I did not change anything in .htaccess. I assume, the problem is somewhere in apache vhost, where I do not have admin access. -
Subpage URLs don't work when using port number
simonsays replied to simonsays's topic in Getting Started
yes, that is my question ? -
Subpage URLs don't work when using port number
simonsays replied to simonsays's topic in Getting Started
Seen this thread, it is irrelevant to my problem as I have already input httpHost value with port in it. It is URL being inproperly rewritten. -
Hello, I have recently finished local development with ProcessWire and moved to DEV VPS. However, DEV VPS base url has port number in it. url:port. So, when I either go to admin url:port/processwire and or any of the subpages, they are not found. Do I need to modify anything in .htaccess or Apache? Does anyone have experience with this?
-
@LostKobrakai When I try to install module using your migration, extra permission declared for this module in getModuleInfo() is not installed automatically. When I install module via admin, permission is added OK. Is this a bug? Or was it done like that intentionally?
-
Okay, found a workaround of assigning title to $original (without saving). That way it worked. Doesn't it feel to be a bit off?
-
protected function copy() { $input = $this->wire('input'); $id = $this->wire('sanitizer')->int($input->post->id); $original = ($id) ? $this->wire('pages')->get($id) : $this->wire('page'); $redirect = $this->wire('page')->path; if ($this->canEdit() && $original) { $original->of(false); $copy = $this->wire('pages')->clone($original, null, false); $copy->title .= ' - Copy'; $copy->save(); if ($original->hasChildren()) { $children = $original->children('include=all'); foreach ($children AS $child) { $this->copyChild($child, $copy); } } $this->sc->flash->success('Page "' . $original->title . '" successfully copied as "' . $copy->title . '"'); $templateTags = array_map('strtolower', explode(' ', $original->template->tags)); if (!in_array('section', $templateTags)) { $redirect = $copy->path; } } $this->wire('session')->redirect($redirect); } Bump! I was still unable to solve the problem. I now have a copy method, which does not use setDummyData and has 100% same problem. Every time a save is performed, image is reset. When I comment out $copy->save(); the image is preserved. Does anyone know a workaround?
-
Like I said, I do not receive an error (know, that page must exists before files are attached), I simply get an empty image. So, I added $page->save() to savePageBasic() (thanks for the optimization advice) to make sure page ID exists by the time image is added public function savePageBasic() { $input = $this->wire('input'); $page = $this->wire('page'); $sanitizer = $this->wire('sanitizer'); if ($input->post->submit && $this->canEdit()) { $p = new Page(); $parent = $page->path; $p->parent = $parent; $p->template = $sanitizer->text($this->input->post->section); $p->addStatus(Page::statusUnpublished); $p->title = $sanitizer->text($input->post->title); $p->save(); return $p; } return false; } The submit() method remained the same public function submit() { $input = $this->wire('input'); $page = $this->wire('page'); $session = $this->wire('session'); if ($input->post->submit && $this->canEdit()) { if (($p = $this->savePageBasic()) !== false) { $p->addStatus(Page::statusHidden); $this->setDummyData($p); $p->save(); $this->sc->flash->success('Page "' . $p->title . '" successfully saved'); } $session->redirect($page->path); } } $p->save() reset the image somehow (commenting it out solves the issue). But that is extremely wrong IMHO.
-
Like I wrote, the image is saved as long as I do not run $page->save() after running setDummyData(). I do not understand, why it empties the image field.
-
Hello everyone, I have two methods inside a class public function savePageBasic() { $input = $this->wire('input'); $page = $this->wire('page'); $sanitizer = $this->wire('sanitizer'); if ($input->post->submit && $this->canEdit()) { $p = new Page(); $parent = $this->wire('pages')->get($page->path); $p->parent = $parent; $p->template = $sanitizer->text($this->input->post->section); $p->name = $sanitizer->pageName($input->post->title); $p->addStatus(Page::statusUnpublished); $p->title = $sanitizer->text($input->post->title); return $p; } return false; } public function submit() { $input = $this->wire('input'); $page = $this->wire('page'); $session = $this->wire('session'); if ($input->post->submit && $this->canEdit()) { if (($p = $this->savePageBasic()) !== false) { $p->addStatus(Page::statusHidden); $this->setDummyData($p); $p->save(); } $session->redirect($page->path); } } /** * Set dummy data to page fields */ protected function setDummyData(&$page) { $dummyData = [ 'FieldtypeTextareaLanguage' => 'Start writing your <b>%s</b> here...<br/>Make sure text is input before you publish...', 'FieldtypeImage' => 'https://dummyimage.com/1200x900/c2c2c2/2e2e2e.png&text=No+image+yet', ]; foreach ($page->template->fields AS $field) { $type = (string)$field->type; if (isset($dummyData[$type])) { $value = sprintf($dummyData[$type], strtolower($field->label)); $page->{$field->name} = $value; $page->save(); } } return true; } I have a page with textarea and single image and a method which sets some dummy data to them. The problem is, that after running $page->save() inside submit() method, image disappears (text stays). Commenting $page->save out of submit() method solves the issue, but this is wrong in my opinion as I might want to have some manipulations after dummy data is set. I checked the output formatting and it stays false throughout the entire cycle. What could be the problem?
-
Good stuff, thanks for the update!
-
Awesome, thanks @LostKobrakai! Saved me a lot of effort and I also became slightly smarter in the process ;)
-
Hello! Thanks for the wonderful module! Does anyone know, how to use it for FieldtypeOptions? Like picking the type (single or multiple) and setting options values. My attempts for this have failed so far. @LostKobrakai
-
You are a superstar!
-
Yes definitely, but first and foremost must properly describe the issue and steps to reproduce. What confuses me, is that cloning perfectly works in admin (that's why I wanted to find that bit in the source code), but not in my method. And in my specific case the parent does not have an image field, but still fails. And I do not understand, how this line $this->pages->save($copy, $options); sets children OF to true. @Robin S what were your steps to reproduce?
-
Apparently your page does not have children or custom fields like mine. I don't think I explained my problem clear enough. For some reason both the page and its children output formatting is set to true. Therefore, cloning fails. Explicitly setting the ORIGINAL (not COPY) formatting to false allows me to copy pages without children. But for some reason, child OF always resets to true. So, when a clone method is called recursively, the $page is set back to of()=true. I have found the problem in the code, but unable to solve it. In PagesEditor.php this code inside __clone method $o = $copy->outputFormatting; $copy->setOutputFormatting(false); $this->pages->cloneReady($page, $copy); $this->cloning++; $options['ignoreFamily'] = true; // skip family checks during clone try { $this->pages->save($copy, $options); } catch(\Exception $e) { $this->cloning--; $copy->setQuietly('_cloning', null); throw $e; } always sets children output formatting back to TRUE. This makes zero sense. The fields are not formatted or changed in any manner, so I strongly suspect a bug. One more option - take a look how admin copies a page with children? Where can I find this code?
-
Without this line it does not work at all (throws the same error, only for a page that is being copied). Setting recursion to true changed nothing.
-
Hello everyone, I am trying to clone a page using PW API. Here's the function: public function copy() { $input = $this->wire('input'); if ($input->post->submit && $this->canEdit()) { $original = $this->wire('page'); $pages = $this->wire('pages'); $original->of(false); $copy = $pages->clone($original); $copy->title .= ' - Copy'; $copy->save(); } $this->wire('session')->redirect($copy->path); } Works fine, when a page does not have children, but fails completely when there are child pages throwing me the following error... Fatal error: Exception: Can’t save page 0: /campaign-demo-1/section-text-image-first/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: text_align (in C:\xampp\htdocs\t2cms\wire\core\PagesEditor.php line 515) #0 C:\xampp\htdocs\t2cms\wire\core\Pages.php(411): ProcessWire\PagesEditor->save(Object(ProcessWire\Page), Array) #1 C:\xampp\htdocs\t2cms\wire\core\Wire.php(386): ProcessWire\Pages->___save(Object(ProcessWire\Page), Array) #2 C:\xampp\htdocs\t2cms\wire\core\WireHooks.php(723): ProcessWire\Wire->_callMethod('___save', Array) #3 C:\xampp\htdocs\t2cms\wire\core\Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Pages), 'save', Array) #4 C:\xampp\htdocs\t2cms\wire\core\PagesEditor.php(1199): ProcessWire\Wire->__call('save', Array) #5 C:\xampp\htdocs\t2cms\wire\core\Pages.php(514): ProcessWire\PagesEditor->_clone(Object(ProcessWire\Page), Object(ProcessWire\Page), true, Array) #6 [internal function]: ProcessWire\Pages->___clone(Object( in C:\xampp\htdocs\t2cms\index.php on line 64 where campaign-demo is the page, that I copy, and section-text-image-first is a child page. I already tried looping through $original->children and setting ->of(false) but to no avail. Does anyone know what the problem might be? Thanks in advance!