• Content Count

  • Joined

  • Last visited

Community Reputation

28 Excellent

About Marc

  • Rank
    Full Member

Profile Information

  • Gender
  • Location

Recent Profile Visitors

1,979 profile views
  1. Thanks for pointing this out, that looks like an acceptable workaround.
  2. I want to have a custom page under Settings in the admin that shows a PageTable field. I have it setup as follows: Created a Process module that installs a page under /admin/settings. This page has the admin template and points to my module's process. A page that has a template which holds the PageTable field. This page holds the children of the PageTable. The execute function of the module renders a form that gets the inputfields from the page I mentionend above. When I execute the module, a form is successfully rendered with the PageTable field. It looks like this: However, after pressing 'Add New' and saving a new item, the form reloads and I see this: The new item is saved but not listed in the field. I also tried this with a repeater field, which has a similar defect. Other types of fields like a text field work fine. When I add the PageTable field to the template of a regular page and edit that page, it works as expected. Only when accessing the field through my Process module's page it does not work correctly. I'm sure there's a fix for this. I think the form does not know what page to link the PageTable entries to perhaps?
  3. Thank you for helping me understand this. Now I managed to get it working! I give my replacement field an exta attribute called 'replaced' and the hook is only allowed to do its job if the field does not have that extra attribute. Like this: wire()->addHookAfter('Inputfield::render', function($event) { if (wire('page')->template != "account") return; $inputfield = $event->object; if ($inputfield->attr('name') == "profile_pad_countrycode" && $inputfield->attr('replaced') != "yes") { $replacement = $this->modules->get('InputfieldSelect'); $replacement->label = 'Land code'; $replacement->attr('name', 'profile_pad_countrycode'); $replacement->attr('class', 'uk-select'); $replacement->attr('replaced', 'yes'); // This is essential to prevent a loop. Check for this value when the hook starts. $optionsArray = ['test']; $replacement->addOptions($optionsArray); $event->return = $replacement->render(); } });
  4. The original text field that I want to replace belongs to a third party module. Rather than changing the field properties of that module, I thought I'd tailor that particular field to my needs with a hook. I agree this might be a bit dangerous and perhaps I'll end up just changing the module, but it's a fun experiment nonetheless. I gave this a try. It doesn't appear to have any effect. I should use this in addition to my own hook, right? Is this hook supposed to prepare PW for the change in field type? I did some more testing and even when I try to replace the text field with a new text field (so same field type), it only works as long as the name of the replacement field is not the same as the original (but then you can't save new values using the new field to the old field). When a form gets rendered and it has the replacement field with the same name as the original field, the server hangs and I'll get this fatal error: Fatal error: Allowed memory size of 268435456 bytes exhausted So at this point I'll rephrase my question: can I replace a field with a new field of the same type and the same name using a hook? Once I get that working, I'll see if I can use a replacement field of another type.
  5. I have a form (outside of the admin) that shows a text field. I want to replace this field with a select field during rendering. The problem is, when I name the replacement field the same as the original, the page stops working. But I'm thinking if I use another name for my replacement field, its value won't be saved to the original field. Here's the hook I'm using in ready.php: wire()->addHookAfter('Inputfield::render', function($event) { if (wire('page')->template != "account") return; $inputfield = $event->object; if ($inputfield->attr('name') == "profile_pad_countrycode") { $replacement = $this->modules->get('InputfieldSelect'); $replacement->label = 'Land code'; $replacement->attr('name', 'profile_pad_countrycode'); // This is a problem, the form crashes when using this name. $replacement->attr('class', 'uk-select'); $optionsArray = ['test']; $replacement->addOptions($optionsArray); $event->return = $replacement->render(); } }); Can this way of replacing an inputfield ever work? Or should I abandon this idea?
  6. Marc

    This module is currently broken. I think it was made with version 1 of the Mollie API in mind. If you use it together with the current version of the Mollie API (v2), it does not work at all. Here's a discription of the API changes from v1 to v2 that I think the developer of this module may want to take a look at.
  7. Marc

    I just ran into this issue with the same PaymentModule module for Padloper. Thanks so much for figuring this out.
  8. Oops, that fixed it. Thank you very much!
  9. I did not include the config part of the module because I did not think it would be relevant. But the Modules::saveConfig hook looks like the hook I need, thanks. I tried it out with a simple test but this does nothing when I save the module configuration (it should diplay a message): class WireDataSetupWebsite extends WireData implements Module { public static function getModuleInfo() { return array( "title" => "Website Options", "summary" => "Setup options for this website.", "author" => "", "singular" => true, "autoload" => true ); } public function init() { $this->addHookAfter('Module::saveConfig', $this, 'test'); } public function test(HookEvent $event) { $arguments = $event->arguments; $this->session->message('this is a test to see if the hook runs'); } }
  10. I want to build a simple module that holds some settings for my website. The easiest way I see is doing this with a WireData module. So I set one up and it currently holds one field called website_type. When this field is saved, I want to do some stuff with the updated value. How do I hook into the save method? I tried the following, showing a message with the updated value (it shows the current value instead): class WireDataSetupWebsite extends WireData implements Module { public static function getModuleInfo() { return array( "title" => "Website Options", "version" => "0.0.1", "summary" => "Setup options for this website.", "author" => "", "singular" => true, "autoload" => true ); } public function init() { $this->addHookBefore('ProcessModule::executeEdit', $this, 'test'); } public function test(HookEvent $event) { $this->session->message('website type: ' . $this->website_type); } }
  11. Marc

    My company developed a website where we sell greeting cards and gift products that our customers can customize and apply their own designs to. The designs can then be previewed in interactive 3D. We use a software package called Taopix 3D Designer for this. Taopix are using three.js to render the preview, so you may want to look into that javascript library as well.
  12. I have setup a template called 'product-collection'. The edit permissions are set by this template and assigned to a user role called 'editor'. 'Allow edit-related access to inherit to children' is enabled. I have another template called 'product-card' with no permissions specified. I have setup two pages, a parent page that has template product-collection and a child with product-card. The user with the editor role can edit this product-card page just fine, so the edit-related settings work as expected. There is an issue with the pagelister though: once the product-card page is unpublished, the editor can no longer list this page unless he specifically sets a filter to include unpublished pages. This is because the pagelister shows this warning beneath the filters: "Not all specified templates are editable. Only 'include=hidden' is allowed". So while the specified template (product-card) IS editable (because it inherits edit-permissions from its parent), the pagelister does not know this. One way around this is by setting the edit permissions of the product-card template manually instead of by inheriting from the parent. If you do this the warning goes away and unpublished pages are listed without setting a status filter. This behavior seems like a bug to me. What do you think? I'm using the latest development version.
  13. I figured it out, hopefully this might be useful to others as well: // Remove current thumbnail first. $currentThumb = $page->image_thumb->first(); $page->image_thumb->delete($currentThumb); // Get the image we want to copy. $original = $page->image_front; $file = $original->getFile($original); // Clone that image and append it to the image_thumb field. $new = $original->clone($file, array('action' => 'append', 'pagefiles' => $page->image_thumb)); $page->save(); I noticed that this does not work if the filename of the file you are trying to clone ends with -0 (e.g. myfile-0.jpg). I think that is a bug which I'll post to GitHub.
  14. I understand I can generate different sizes and that is exactly what I'm doing right now. I do some checks to see if the uploaded thumbnail is of high enough quality by checking its dimensions and if it is not, I fallback to the image_front field which is always of higher quality and I resize on the fly to the correct dimensions. I want to get rid of these checks so I want to do a one time replacement of a bunch of thumbnails by cloning the image_front image to the thumbnail field.
  15. I want to use the API to duplicate an image from one field to another (on the same page). The duplicated image should be a new file so both fields should not point to the same physical file. The field that holds the image that I want to duplicate is called 'image_front' and the duplicated image should go to a field called 'image_thumb'. Any image that is already attached to image_thumb should be removed because it should hold only one file. The same goes for image_front, it should have only one image. Here's what I have so far: $original = $page->image_front; $file = $original->getFile($original); $new = $original->clone($file); $page->save(); $page->image_thumb = $new; $page->save('image_thumb'); This works in the sense that the image is successfully cloned but it is attached to both fields so both fields end up have their original image plus the cloned image. 'Image_thumb' should only have the cloned image and 'image_front' should only have the original image. What would be the best way to remove those images and am I even approaching this correctly?