Jump to content

Xonox

Members
  • Content Count

    91
  • Joined

  • Last visited

Community Reputation

43 Excellent

About Xonox

  • Rank
    Full Member

Recent Profile Visitors

2,160 profile views
  1. 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!
  2. 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! 😞
  3. 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. 😞
  4. 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".
  5. 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! 😞
  6. 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!
  7. 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!
  8. 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.
  9. Thinking about this alternative. This might work better. So now I have a working code inside _init.php: // Activity form if($page->template == 'activity') { $forms->addHookBefore('FormBuilderProcessor::renderReady', function($e) { $form = $e->arguments(0); if($form->name == 'activity_form') { // Get Atividade field $inputfield = $form->getChildByName('atividade'); // I NEED TO INSERT A SELECTED OPTION HERE // something something = $page->id; } }); $activity_form = $forms->render('activity_form'); } Getting close. Can someone help?
  10. Hi @elabx, Thanks for your reply. I really need some help here, working with Hooks. First, watching the function you showed me, I believe that the responsible bit for not having the self page in the selector is the last part. So it's not a bug, but a feature (not sure why). This are the lines I need to override.: if($children && $children->has($page)) { $children->remove($page); // don't allow page being edited to be selected } I was playing around with the hooks but I couldn't figure it out. Form builder doesn't have a InputFieldPage Hook, so how am I supposed to hook into it? The code below must be completely wrong, my apologies, but I'm completely lost here (I have this inside _init.php): if($page->template == 'activity') { // This hook will make sure that the list of pages include self page $this->addHookBefore('InputfieldPage::getSelectablePages', function($event) { $children = $pages->get('parent=1066'); return $children; }); $activity_form = $forms->render('activity_form'); } Can someone point me to the right direction? Thanks! Alternative When rendering the select field, add current page and make it selected. Is this possible?
  11. Hi, I'm having a problem with a page selection field. I have the following tree set up: Activities - Activity 1 - Activity 2 - Activity 3 - Activity 4 So I created a form where you can select one of the activities on which you would like to participate. For usability purposes, the form is inserted in each Activity page, so that the user doesn't have to click to get to a form. I have two problems (let's say the user is inside the "Activity 2" page); 1. Inside the form, where the user can select the activity, the current page is not listed, so the user can select "Activity 1", "Activity 3" and "Activity 4", but not the one in which he is. This one might be a bug. 2. It would be nice that the activity in which he is - Activity 2 - Would be selected by default. Is there any way that I can accomplish this without a custom markup form? Thank you.
  12. @adrian, thanks for your help. The examples given weren't really helping because the file name wasn't kept. For each time de file was replace it would add "-1", "-2" etc. to the file name. I managed to make it work and I am posting the code, in case someone needs something like this. foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Check if image already exists $replace = false; foreach($book->book_images as $image){ // Replace image if($file == $image) { $book->book_images->delete($image); $book->save(); $book->book_images->add($upload_directory . '/' . $file); $book->save(); // Place image in the right position: after previous or as first if(isset($previous_image)) { $old_item = $book->book_images->get($previous_image); $new_item = $book->book_images->last(); $book->book_images->insertAfter($new_item, $old_item); } else { $old_item = $book->book_images->first(); $new_item = $book->book_images->last(); $book->book_images->insertBefore($new_item, $old_item); } $replace = true; } $previous_image = $image; } // Add image to book if(!$replace) { $book->book_images->add($upload_directory . '/' . $file); } // Save book $book->save(); // Delete processed file unlink($upload_directory . '/' . $file); } } }
  13. @adrian thank you very much for your help, so far. However, it doesn't seems to be working: $book->book_images->replace($book->book_images->path . $image, $upload_directory . '/' . $file); Doesn't return any error but it doesn't replace the image! 😞
  14. Hi, Thank you for your help. Here's what I've got so far and working: foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Check if image already exists foreach($book->book_images as $image){ // Remove existing image if($file == $image) { $book->book_images->remove($image); $book->save(); } } // Add new image $book->book_images->add($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } } The only problem with this code, is that the new image doesn't keep the same order. It's always added at the end. Is there any way to make it load into the same position?
  15. Hi, I'm trying to upload images from a folder into a page. I need to replace the images instead of adding. The image field already has the replace existing images turned on, but it doesn't seem to be enough. My code: foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book !!! THIS CODE ADDS FILE INSTEAD OF REPLACING. HOW CAN I REPLACE? $book->book_images->add($upload_directory . '/' . $file); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } } What am I missing?
×
×
  • Create New...