Jump to content

Xonox

Members
  • Posts

    98
  • Joined

  • Last visited

Recent Profile Visitors

3,502 profile views

Xonox's Achievements

Full Member

Full Member (4/6)

46

Reputation

1

Community Answers

  1. @monollonom, how did I miss that?!?! Thanks for calling it to my attention. That would have save me all that work! Although, maybe, in the future other templates might be needed, so it's not going to waste... maybe! 😄
  2. @cwsoft thanks a lot for your help. It turned out to be a bit more complex than what you posted, unfortunately! I'm leaving the full code here, if anyone needs it. // Automatically generate a name for a new race page, // so the user doesn't go throught this step. // It will immediately land on the page editing screen with the page // already created $wire->addHookBefore('ProcessPageAdd::execute', function(HookEvent $event) { $input = wire('input'); $pages = wire('pages'); $session = wire('session'); // Let's generate a random string to append to name and avoid collisions $rand = random_int(0,9) . chr(random_int(97,122)) . random_int(0,9) . chr(random_int(97,122)); // Only when opening the Add New screen (GET request, no form submit yet) if(!$input->requestMethod('GET')) return; $parentID = (int) $input->get('parent_id'); if(!$parentID) return; $parent = $pages->get($parentID); if(!$parent->id) return; // Parent only allows "race" anyway, but let's be explicit $template = wire('templates')->get('race'); if(!$template) return; // Optional safety: only do this when the template is allowed under this parent if(!$parent->template->childTemplates || !in_array($template->id, $parent->template->childTemplates)) return; // Create page $p = new Page(); $p->template = $template; $p->parent = $parent; // Name must be unique + sanitized (prefix avoids numeric-only names) $p->name = 'race-' . time() . '-' . $rand; // Keep it unpublished until user saves/publishes $p->addStatus(Page::statusUnpublished); $pages->save($p); // Redirect straight to edit screen $session->redirect($p->editUrl); // Stop normal ProcessPageAdd rendering $event->replace = true; $event->return = ''; });
  3. Hi everyone, I'm trying to achieve the following (for the template="race") in the back-end: User clicks "New"; Instead of seeing the Title and Name fields, it just creates the page with an automatic name (timestamp) and goes to page editing with the fields he needs. I'm doiing this because the title and the name are not really important for this content, and I don't want the back-end user to be bothered with information that is not clear to him. I already made the title not mandatory, so only the name should be set up. I have this code, that is not working: // Automatically generate a name for a race, so the user doesn't go throught this step $this->addHookAfter('ProcessPageAdd::execute', function($event) { // Get the page being created $page = $event->arguments(0); if($page->template->name == 'race') { // Turn off output formatting $page->of(false); // Make the timestamp as the page name and move on $page->name = time(); $page->save(); } }); For what I understand, at this point the page doesn't exist yet, so that's probably why this is not working. So I'm not really sure how to use the hooks to: attribute the name; save the page.
  4. Hi, @Zeka Thanks for your reply. Unfortunately the page cloning wasn't going through that page. It just cloned the existing page and displayed it in the tree. Apparently, there's some problem about the permissions. SOLUTION: Instead of giving Clone Permissions to just the templates you want to allow to clone, you should authorize page-clone for all editable templates and revoke all the templates except the ones you want to allow. This allowed the users to go through the clone page and select which options they want.
  5. Update: Clearly, the problem happens only with pages that have sub pages. Is there anyway I can clone a page, without cloning sub-pages?
  6. It looks that pages that have subpages can't be cloned?!?! Is there anyway that I can circumvent this? I would like to clone a page without the subpages.
  7. After some years with a website working perfectly, Page Clone started to display some strange behaviour: 1. When cloning some pages, it takes forever. The waiting icon is displayed but the page never appears. Only after I refresh the tree page, the new page appears: 2. The other thing is that some pages can't be copied. The pages have the same templates but the users are able to copy some and other don't. It gives this error: (the URL is .../page/clone/?id=76376&login=1) Does someone have a clue why this is happening. I can't find any real difference between the pages that I'm trying to copy. One more thing: If the user is a super user, he's able to copy every page without problems. I think both errors might be related. Thanks!
  8. Changing table to InnoDB solved it! Hi, that's what worked, for me, changing that one table (pages) into InnoDB. Because it was an issue that needed time, to see if it would happen again, I didn't update this issue. Hope this helps you!
  9. Update: If the field is outside a repeater, it works fine! In my dev server, everything works fine inside the repeater. In production server, the field inside the repeater doesn't work as it should. Inside repeater, I can't even edit image descriptions. Field outside the repeater works fine on both machines. I just remembered that I had this problem before, on another site, but never got solved: This is getting a bit annoying! ?
  10. It looks related, but I still can't get it to work. There are some new inputs: 1. The field is inside a repeater; 2. Despite the field being set to have only one image, in some cases it has more than one that I can't delete; 3. Tried to change files' permissions but it still doesn't work; 4. It's impossible to delete the images, but when I load a new one, it replaces one of the old ones. I'm a bit lost with this one. ?
  11. Update: I also can´t delete the slide_image_mobile images, which should be unique (only one image). It keeps adding images despite the field being set with only one image and "One element null if empty".
  12. I checked and it looks fine. To clarify: slide_image - is detected and used; slide_image_mobile - site behaves as it doesn't exist! Both have same permissions. I changed the code to the following to force the use of slide_image_mobile: foreach($page->home_slides as $slide) { $slide_image_mobile = $slide->slide_image_mobile->size(1048,800); ?> <img src="<?php echo $slide_image_mobile->url; ?>" class="img-fluid d-block d-md-none" title="<?php echo $slide->slide_title; ?>" alt="<?php echo $slide->slide_title; ?>" /> <?php } Which gives a Fatal Error (Call to a member function size() on null) which makes sense. But the image is there! ?
  13. Hi, There's something happening in ProcessWire that doesn't compute abd it has to do with images. Situation: On the homepage template there's a repeater that takes two images to build a slider: slide_image: A wide image for desktops slide_image_mobile: A more "verticalized" image for small screens Now I have this code: foreach($page->home_slides as $slide) { // Create desktop slide if(isset($slide->slide_image)) { // Create desktop slide $slide_image = $slide->slide_image->size(1170,400); // Create mobile slide if(isset($slide->slide_image_mobile)) { $slide_image_mobile = $slide->slide_image_mobile->size(1048,800); } else { $slide_image_mobile = $slide->slide_image->size(1048,800); } ?> <div class="slide-content"> <a href="<?php echo $slide->link; ?>" class="slide"> <img src="<?php echo $slide_image->url; ?>" class="img-fluid d-none d-md-block" title="<?php echo $slide->slide_title; ?>" alt="<?php echo $slide->slide_title; ?>" /> <img src="<?php echo $slide_image_mobile->url; ?>" class="img-fluid d-block d-md-none" title="<?php echo $slide->slide_title; ?>" alt="<?php echo $slide->slide_title; ?>" /> </a> </div> <?php } } On my dev server, the small image is detected and placed in content, however in my production server this doesn't happen. I've double checked fields names and the fields contain images. I've even imported the database into the Dev Server. I don't have any clue why it works locally and not in server. Can anyone shed som light? Thank you!
  14. Bingo! In case someone needs it: // Activity form if($page->template == 'activity') { $forms->addHookBefore('FormBuilderProcessor::renderReady', function($e) { $form = $e->arguments(0); if($form->name == 'activity_form') { $page = wire('page'); // IS THIS RIGHT? $selected = array(); // IS THIS RIGHT? $selected['selected'] = 'selected'; // IS THIS RIGHT? // Get Atividade field $inputfield = $form->getChildByName('atividade'); // Get InputfieldPage $select_field = $inputfield->getInputField(); // Get the correspondent InputfieldSelect $select_field->addOption($page->id, $page->title, $selected); // Add current page as selected option } }); $activity_form = $forms->render('activity_form'); } Thanks for your help @elabx, it made all the difference!
  15. So close and yet so far! if($form->name == 'activity_form') { // Get Atividade field $inputfield = $form->getChildByName('atividade'); $page = wire('page'); $inputfield->addOption($page->id, $page->title, array('selected')); } Two problems: 1 - $page = wire('page'); is this the best way to have access to the page id and title inside the hook? Is there a performance issue? 2 - Error on addOption: Error: Exception: Method InputfieldPage::addOption does not exist or is not callable in this context (in E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php line 519) #0 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(386): ProcessWire\Wire->___callUnknown('addOption', Array) #1 E:\WebServer\clinicadasconchas.pt\wire\core\WireHooks.php(723): ProcessWire\Wire->_callMethod('___callUnknown', Array) #2 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldPage), 'callUnknown', Array) #3 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(445): ProcessWire\Wire->__call('callUnknown', Array) #4 E:\WebServer\clinicadasconchas.pt\site\assets\cache\FileCompiler\site\templates\_init.php(31): ProcessWire\Wire->__call('addOption', Array) #5 E:\WebServer\clinicadasconchas.pt\wire\core\WireHooks.php(813): ProcessWire\TemplateFile->{closure}(Object(ProcessWire\HookEvent)) #6 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(442): ProcessWire\WireHooks->ru It looks like it is a InputfieldPage field, and this doesn't have addOption method.
×
×
  • Create New...