Jump to content

fruid

Members
  • Posts

    680
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by fruid

  1. I'm having the same issue: ProcessModule: Invalid module name: “.Modules.info” Please use uppercase [A-Z] for first character, lowercase [a-z] for 2nd character, and [a-z A-Z 0-9] for the rest. For example: “Modulesinfo” ProcessModule: Invalid module name: “.Modules.site/modules/” Please use uppercase [A-Z] for first character, lowercase [a-z] for 2nd character, and [a-z A-Z 0-9] for the rest. For example: “Modulessitemodules” ProcessModule: Invalid module name: “.Modules.wire/modules/” Please use uppercase [A-Z] for first character, lowercase [a-z] for 2nd character, and [a-z A-Z 0-9] for the rest. For example: “Moduleswiremodules” ProcessModule: Invalid module name: “.ModulesUninstalled.info” Please use uppercase [A-Z] for first character, lowercase [a-z] for 2nd character, and [a-z A-Z 0-9] for the rest. For example: “ModulesUninstalledinfo” ProcessModule: Invalid module name: “.ModulesVerbose.info” Please use uppercase [A-Z] for first character, lowercase [a-z] for 2nd character, and [a-z A-Z 0-9] for the rest. For example: “ModulesVerboseinfo” ProcessModule: Invalid module name: “.ModulesVersions.info” Please use uppercase [A-Z] for first character, lowercase [a-z] for 2nd character, and [a-z A-Z 0-9] for the rest. For example: “ModulesVersionsinfo However I don't know where exactly this is coming from and am also not sure what is supposed to follow this name scheme. The title? The class name? The .module.php file name? Because all the module classes I see have CamelCase with the first letter Uppercase, so do the module file names and the titles have Title Case and normally allow for spaces too… Thanks for help!
  2. Yes, my bad, It happened because I downgraded to an older version of ProcessWire unintentionally when moving things around. Cheers
  3. I have an issue ProcessModule: Module “ProcessPageViewStat” exists in database but not on the file system. Consider placing the module files in /site/modules/ProcessPageViewStat/ or removing the module from the database. But whether I delete it from the database or add the module folder to the modules folder, in both cases I get: Hmm… Fatal Error: Uncaught Error: Call to a member function render() on null in wire/modules/Process/ProcessModule/ProcessModule.module:995 And can't do anything else anymore… What to do? I'm lost…
  4. OK, trying to answer my own question, Below is my so far working solution, the code I put on ready.php things to note: - it doesn't log and therefor doesn't render error messages - I tried to put that in a separate module, but the problem seems to be, that both hooks would call methods from two different classes, so for the first hook I would need to extend the Wire class and for the second the Process class. Two modules for this simple functionality seems a bit overkill and then it can only do this… - Maybe a better idea would be to extend the Diagnostics-module directly? Which ever one makes sense. (ProcessDiagnostics, DiagnoseModules, …) - in order to make this code work, you'd still need to make the method GetDiagnostics hookable, so add ___ to GetDiagnostics in DiagnoseModules (I know, it's a hack) // ready.php $this->addHookAfter('DiagnoseModules::GetDiagnostics', function ($event) { wire('log')->delete('diagnostics'); $results = $event->return; // Loop through results and extract the entries that are warnings and failures and log them foreach ($results as $result) { if ($result['status'] != '') { wire('log')->save('diagnostics', $result['status'] . ': ' . $result['title'] . ' - ' . $result['value']); } } // Return the modified results $event->return = $results; }); function formatDiagnosticMessage($line) { $lineParts = explode(':', $line); $severity = $lineParts[0]; $message = $lineParts[1]; $formattedMessage[0] = $severity; $formattedMessage[1] = $message; return $formattedMessage; } $this->addHookBefore('PageRender::renderPage', function(HookEvent $event) { // Get the object the event occurred on, if needed $PageRender = $event->object; // Get values of arguments sent to hook (and optionally modify them) $event = $event->arguments(0); $page = $event->page; $info = ' - check Diagnostics-module for further investigation.'; if ($page->template != 'admin') return; $ProcessDiagnostics = wire('modules')->get('ProcessDiagnostics'); if (!file_exists('site/assets/logs/diagnostics.txt')) { $this->message('No warnings or errors found' . $info); return; } $diagnosticsFile = fopen('site/assets/logs/diagnostics.txt', 'r'); $diagnosticsLines = []; while (($line = fgets($diagnosticsFile)) !== false) { $diagnosticsLines[] = $line; } fclose($diagnosticsFile); foreach ($diagnosticsLines as $line) { $parts = explode(' ', $line); $formattedMessage = formatDiagnosticMessage($parts[3]); if ($formattedMessage[0] == 'Warning') { $this->warning($formattedMessage[0] . ': ' . $formattedMessage[1] . $info); } if ($formattedMessage[0] == 'Failure') { $this->error($formattedMessage[0] . ': ' . $formattedMessage[1] . $info); } } $event->arguments(0, $event); });
  5. I want to hook into the module and log the warnings and failures, is that doable? This is what I tried with no luck: //ready.php $this->addHookAfter('ProcessDiagnostics::___collectDiagnostics', function($event) { // Get the instance of the ProcessDiagnostics module $module = $event->object; // Get the title, value, status, and notes from the hook event $title = $event->argument('title'); $value = $event->argument('value'); $status = $event->argument('status'); $notes = $event->argument('notes'); // Log the information to the console wire('log')->save('diagnostics', $title); wire('log')->save('diagnostics', $value); wire('log')->save('diagnostics', $status); wire('log')->save('diagnostics', $notes); });
  6. is there a way to select pages by some (usually the current, or user?)-language specific value only? I'm aware that there's a method that I can use, but I'd prefer to use a selector, if possible. so instead of $results = new WireArray; $query = "banana"; $indexed = $pages->find("template=some_template"); foreach ($indexed as $p) { if ($p->getLanguageValue("english", "title|headline[preview|body") == $query { $results->add($p); } } I'd like to something like: $query = "banana"; $results = $pages->find("template=some_template, title|headline|preview|body=LanguageValue("english", $query)"); or $results = $pages->find("template=some_template, title_1021|headline_1021|preview_1021|body_1021=$query"); thanks for help!
  7. how would make a custom page class for the template basic-page ? basic-pagePage? Basic-pagePage? Basic-PagePage?
  8. can I generate an InputfieldAsmSelect to select pages from the page-tree?
  9. I have a weird issue I have a couple of PageArray objects of which, when I do a print_r, the children are all not at the [items] but at the [items_removed] key/position, seemingly at random. In the page tree everything looks normal (not hidden or unpublished or in the trash) and everything looks just like all the other PageArray obects with no issue. Any ideas what that could be?
  10. I know I'm sort of preaching to the choir here, but it's a shame you cannot add images in SF. I think what many devs, me included ,want to use this module for is for global settings which includes things like logo(s). It just makes so much more sense to have these things defined in a separate page rather than by adding fields to the home template but maybe I'm just being too neurotic. Please forgive me if this is a dumb question, but since I have to create a page under the admin page tree to get SF to work, why can't I add images to this very site's /assets/files/ folder? But I guess the answer does something like because the fields I create on the required php or json file don't really exist in the system and are create at runtime?
  11. I tried that, FYI I see PHP Warning: Undefined array key "footer_imprint__1021" in .../modules/SettingsFactory/ProcessSettingsFactory.module:151
  12. yes of course, I remember now Thanks!
  13. has something changed in this module? Because I cannot seem to find the place where you enter the path to the json or php file with the settings array. I'm on ProcessWire 3.0.207
  14. I'm having some difficulties understanding how this works and getting started. So I installed Vue JS inside a folder in /site/templates/scripts/vue/ created a vue app inside of that folder and did vue add vuetify I followed the instructions in the official vuetify guide and did a npm run build Anyways, I miss the part where I include the vuetify .css and .js files in the <head> or <body> tag respectively. Which files do I need to include?
  15. thanks @LMD for your feedback, yes I assumed there must be a lot of overhead in my code the way it is now. I will update it soon to use SQL commands and update it probably again once meta is accessible via selectors.
  16. thanks @bernhard, yes I noticed that later on. I managed to get the module to serve my needs, it's here: https://github.com/dtjngl/MenuAllocator I (re)watched your hook-tutorial, it's interesting but I doubt it can help me in this very use-case since I do not really populate fields on the page and the fields in question are rendered at runtime (by a another hook), so I had a hard time saving the values to the page (luckily there's ->meta). I'm not sure if this is the best approach but it works. @everyone, please give it a try, I'd love to get feedback.
  17. public function ready() { $this->addHookAfter('ProcessPageEdit::buildFormContent', $this, 'addCustomFieldToPageEditForm'); // ... } public function addCustomFieldToPageEditForm(HookEvent $event) { $page = $event->arguments('page'); // null // ... } ;( EDIT: $id = $this->input->get('id'); // frontend page object id $page = wire('pages')->get($id); // frontend page object 😄
  18. doesn't work 😞 should be so easy though, right? class MenuAllocator extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Menu Allocator', 'version' => 1, 'summary' => 'A module to allocate menus to pages.', 'autoload' => 'template=admin', ); } public function ready() { // Add a hook to build the page edit form content $this->addHookAfter('ProcessPageEdit::buildFormContent', $this, 'addCustomFieldToPageEditForm'); // Add a hook to process the form input when the page is saved $this->addHookBefore('Pages::saveReady', $this, 'saveCustomField'); } public function init() { bd($this->meta); } public function addCustomFieldToPageEditForm(HookEvent $event) { $form = $event->return; // Check if this is a frontend page (you can define your criteria here) if (strpos($this->input->url, '/admin/') !== false) { // Create the custom field as an InputfieldText $field = $this->modules->get('InputfieldText'); $field->name = 'custom_text_field'; // Use a different name for rendering $field->label = 'Custom Field for Display'; // Different label for rendering $field->description = 'Enter a custom value for this page (display only).'; // Add the field to the page edit form $form->add($field); } } public function saveCustomField(HookEvent $event) { // Get the page object from ProcessWire's API $page = wire('page'); // Check if the page object exists if ($page instanceof Page) { // Get the custom_text_field value from the form input $fieldValue = $this->input->post->custom_text_field; // Use the correct field name // Set the custom field value to the page's meta data $page->meta->set('custom_text_field', $fieldValue); // Use the correct field name for meta data } } }
  19. I can try that, I'm just trying to understand why my approach doesn't work. Why does a similar logic work for editing templates but not for editing pages?
  20. in the module or module config/settings, I want to define an array of "menus". Then, on every page in the page tree, except on pages inside "Admin", I want to render an array of checkboxes (InputFieldCheckboxes), one for each entry in the predefined "menus"-array. When the content manager edits a page they will see these checkboxes, and one or more before saving the page will naturally be saved somewhere, ideally as a property of the page. When creating the menus in the markup (e.g. top menu, footer, sidebar, you name it), one should be able to select the pages according to the values set for said field on the pages. I'm not sure if creating adding a field and adding it to a fieldgroup and template is necessary (also this approach is quite prone to errors, I have to consider __install() and __uninstall() etc.), I managed to accomplish something very simliar with a different module (https://github.com/dtjngl/simpleSearch/blob/main/SimpleSearch.module.php), the difference was, that one renders a text field on each template and when editing a template, the entered value gets saved to the template object. Works like a charm. Thanks for you input!
  21. public function saveCustomField(HookEvent $event) { $fieldValue = $this->input->post->menus; bd($fieldValue); ... $page->set('menus', $fieldValue); } the fieldValue is null when no checkbox is ticked, if first checkbox is ticked it stores an array like so: array (0 => 'top') which is what I expect. My guess is one of the following - I cannot pass just pass an array to a $page->set() method - I misconfigured the hooks - Since I hook a function and edit the saved value I need to return the edited object - I cannot save the value to the page cause the field does not actually live on the page - something about the InputFieldCheckboxes API that works entirely different
  22. Thanks @Mike-it for your suggestion! Before I continue I would like to understand one thing. Is it even possible to render a field on the page-edit page and save its value to the page? As to my understanding it should, because a page is an object and I can add properties to a page object with code as well, so why not with the UI? Or do I need to, upon installing the module, create a field, add it to a fieldgroup and a template and, optionally, remove it accordingly when uninstalling?
  23. Hello everyone, I'm working on a custom ProcessWire module, and I've encountered an issue with checkbox values. The checkboxes render correctly in the page edit form, but when I tick them, save the page, and then reload it, the selected values are not saved to the page. I've tried various approaches, including hooks, to ensure that the selected values persist in the database, but so far, I haven't been successful. I'm seeking advice and solutions to resolve this issue and ensure that the checkbox values are properly saved when a page is edited. Any help or suggestions would be greatly appreciated! Thanks in advance! I wish you a nice Sunday otherwise. class MenuAllocator extends WireData implements Module, ConfigurableModule { public static function getModuleInfo() { return array( 'title' => 'Menu Allocator', 'version' => 1, 'summary' => 'A module to add a custom field to page edit forms.', 'autoload' => 'template=admin', ); } public function __construct() { $menuAllocatorSettings = wire('modules')->getConfig($this); foreach ($menuAllocatorSettings as $key => $value) { $this->$key = $value; } } public function init() { // Add a hook to build the page edit form $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addCustomFieldToPageEditForm'); // Add a hook to save the field value when the page is saved $this->addHookBefore('Pages::executeSave', $this, 'saveCustomField'); } public function addCustomFieldToPageEditForm(HookEvent $event) { $this->message('this is addCustomFieldToPageEditForm'); $page = $event->object->getPage(); // Check if this is a frontend page (you can define your criteria here) if (strpos($page->path, '/admin/') !== 0) { // Get the selected menu names from the module's settings $menuNames = $this->menus; if ($menuNames == '') return; $menuNames = explode(' ', $menuNames); // Create the custom field as an InputfieldAsmSelect $field = $this->modules->get('InputfieldCheckboxes'); $field->name = 'menus'; $field->label = 'Menus'; $field->description = 'Select menu names for the page.'; // Add menu options based on module configuration foreach ($menuNames as $menuName) { $field->addOption($menuName, $menuName); } // Add the field to the page edit form $form = $event->return; $form->insertBefore($field, $form->getChildByName('title')); // Adjust the position as needed } } public function saveCustomField(HookEvent $event) { $page = $event->arguments[0]; // Check if this is a frontend page (you can define your criteria here) if (strpos($page->path, '/admin/') !== 0) { // Get the field value from the input $fieldValue = $this->input->post->menus; // Use the correct field name $this->message($fieldValue); // Save the field value to the page $page->set('menus', $fieldValue); // Use the correct field name } } }
  24. I think it had to do with when the page loads. Running the above function later than in init() workes as expected, there doesn't even seem to be a need for the API calls that target the specific language value, PW does that automatically with the selector after all ^^ However, here's a very similar requirement, therefor I use the same thread to discuss it. class MyModuleConfig extends ModuleConfig { public function getInputfields() { $inputfields = parent::getInputfields(); $f = $this->modules->get('InputfieldText'); $f->attr('name', 'foo'); $f->useLanguages = true; // This enables multilingual support $f->columnWidth = 100; $inputfields->add($f); return $inputfields; } } class MyModule extends WireData implements Module, ConfigurableModule { public function bar() { $foo = $this->foo; echo $foo; // always returns the default language of the page, not even } } I'm able to create a multilanguage field in the module's settings but I am not able to return the page language specific value in the frontend. What am I doing wrong? Thanks for your help again. P.S. I hope you're enjoying your summer so far.
×
×
  • Create New...