Jump to content

gebeer

Members
  • Posts

    1,394
  • Joined

  • Last visited

  • Days Won

    39

Everything posted by gebeer

  1. Thanks for sharing this. Looking at the implementation of parentPrevious inside wire/core/Page.php I thnk your solution is perfectly viable and the parentPrevious property was implemented so we can use it in circumstances like these. At which point in your logic are you using the bypassSaveHook session variable to prevent loops, is it inside a different hook to Pages::save? And since you are inside a Pages::saveReady hook, I think you do not need to set $page->of(false) because output formatting is already turned off at that stage. Also you do not need to do $page->save() because this is happening after the hook was executed and the page is saved with the values that you assigned inside the saveReady hook. So the loop most likely is being caused by the redundant $page->save(). Try removing that line and see if you need the bypassSaveHook session variable at all.
  2. When you tested in the fresh PW install, did you also copy all the code in site/templates, site/ready.php, site/init.php from the affected install to the fresh install? Or in other words, can you rule out with certainty that template or hook code might be responsible, especially hooks? I once stumbled over a similar or at least related problem, where all PW queries in the page tree, that are done via ajax returned an error and pages tree stopped working. Then I discovered that an addHookBefore('ProcessHome::execute', $this, 'rootPage') was responsible. In my hook function 'rootPage', I had to do an if($this->config->ajax) return; This is just what came to my mind when reading about your problem. Did you follow the "Optimize" link and which table is this warning referring to? How many entries are there in the DB table "pages"? I can totally understand your frustration and think we all have been there at some point. But, at least for me, all those situations were resolvable in the end. Even if we cannot charge our clients for the effort we put in resolving those issues, these situations can help us to learn and get better at what we are doing.
  3. Why did you create a new user account to ask the same question like again? This could be considered spam. You should better ask follow up questions in your first thread. Did you read @millipedia's answer? It pretty much explains how you would go about. For rendering your "pagination" links you can use something like this simplified sample code: foreach ($mygallery as $gallery) { echo "<a href='{$mygallery->url}{$gallery->title}'>{$gallery->title}</a>"; }
  4. @horstwould be awesome if you could add a doc block to https://github.com/horst-n/WireMailSmtp/blob/bc2432096704b3ffeab8176d558e211a544f9837/WireMailSmtp.module#L808 so we get some intellisense of what the array actually looks like.
  5. Taken from getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses, So you can check with the 'recipientsFailed' entry of the array if anything went wrong. $result = $mail->getResult(); if(count($result['recipientsSuccess']) { // logic for successful mails } if(count($result['recipientsFailed']) { // logic for failed mails } Or you can use return value of ->send() which returns the count of successfully sent mails or 0 on fail: $numberSentMails = $mail->send(); Log these numbers somewhere and add some logic to your send script that counts how many mails have been sent on the current day, adds them to a mail queue or whatever you need.
  6. I can confirm that not all TinyMCE toolbar options are available in the PW version (e.g. save, formatselect). I couldn't even find out how to add separators in the toolbar through field configuration screen in PW. So your implementation is the way to go if you want those customisations.
  7. Multiple problems with your code. in the last code sample you used InputfieldSelect. Now you are using InputfieldText. The latter will give you a text input and has no method setOptions() you set the options before you define $location $fields->location->$label needs to read $fields->location->label Here is working sample code for a form with location select as only field: // define form /** @var InputfieldForm $form */ $form = $modules->get('InputfieldForm'); // define location first before you can use setOptions() /** @var InputfieldSelect $location */ // you need to use InputfieldSelect here, InputfieldText has no setOptions() method $location = $modules->get('InputfieldSelect'); $location->attr('id+name', 'location'); $location->label = $this->_($fields->location->label); $location->required = 1; $location->attr('required', 'required'); // build options array $optionsArray = $pages->findRaw('template=location', 'title'); // set options to the select field $location->setOptions($optionsArray); // add field to your form $form->add($location); echo $form->render(); // will print out the markup for the whole form I left out the whole fhSanitzer stuff and the hook. Let's go step by step and first make the inputfield work. You need to adjust this to the rest of your code. If you want to have a standalone field, not inside a form you would do something like this: $location = $modules->get('InputfieldSelect'); $location->attr('id+name', 'location'); $location->label = $this->_($fields->location->label); $location->required = 1; $location->attr('required', 'required'); // build options array $optionsArray = $pages->findRaw('template=location', 'title'); // set options to the select field $location->setOptions($optionsArray); // print markup echo $location->render(); This will give you markup like: <select id="location" class="required" name="location" required="required"> <option value="">&nbsp;</option> <option value="1001">Location 1</option> <option value="1002">Location 2</option> <option value="1004">Location 3</option> </select>
  8. FieldTypeOptions gives you different UI and stores data in a different way. If you just need a checkbox, I'd go with InputfieldCheckbox. Less overhead.
  9. You would use $county->setOptions($optionsArray) to populate the select options. Example: /** @var array $optionsArray */ $optionsArray = $pages->findRaw('template=basic-page', 'title'); // returns an array with page ids as keys and page titles as value $county->setOptions($optionsArray); // each option will have value="{pageID}" and label page title You need to adjust the selector to your needs.
  10. Yes it can, but not via the field settings in the GUI. You can put this hook code in site/templates/admin.php above the require($config->paths->core . "admin.php"); line: // sets field checkbox to checked on new pages with template basic-page $wire->addHookAfter('Pages::saveReady', function (HookEvent $event) { /** @var Page $page */ $page = $event->arguments(0); if ($page->isNew() && $page->template->name == 'basic-page') { $page->checkbox = 1; } }); You just need to adjust template and field name. Everytime a new page with that template is created the checkbox will be checked by default. If you have TracyDebugger installed, you can do this with a one-liner in the Tracy console in the backend: $pages->find('template=basic-page, include=all')->each(function($p) { $p->setAndSave('checkbox', 1); });
  11. @Heinzregarding communication via http-requests with the PW backend for retrieving, storing, patching etc with a Rest-ful approach you could use this module: https://processwire.com/modules/app-api/ For building custom frontend forms there is an excellent thread: It is a long thread but a nice read for bored people 😉
  12. I personally can live with this behaviour but still would consider it a bug since it is unexpected. Inputfields should open/close independently whether they are in the same row or not.
  13. Your textformatter seems like a valid solution. Although I am not sure whether the regex for getting the file URL is 100% reliable. I'm not a regex prof. But in general it is not a good idea to rely on regex for parsing HTML. You could use PHP's SimpleXML to parse and replace the href attributes. Adapt something like this: https://stackoverflow.com/questions/27326066/simplexml-php-change-value-from-any-node But I think you don't even need a textformatter for the task. A simple hook will intercept all URLs to PDF files and return the desired URL under /downloads/. Place this in site/init.php <?php namespace ProcessWire; // intercepts all file URLs and rturns URLs in desired format. wire()->addHookAfter('Pagefile::url', function(HookEvent $event) { /** @var PageFile $pageFile */ $pageFile = $event->object; if(strtolower($pageFile->ext) === 'pdf') { $pageId = $event->page->id; $event->return = '/download/' . $pageId . '/' . $pageFile->basename; } }); Now all URLs to PDF files will have the desired format. Even when you add a link to a file inside CKE editor, the desired URL will inserted.
  14. Hello and welcome to the forum! Please try to post in English if possible. Thank you. Is your code inside a function? If not, you need to echo json_encode($res) return json_encode ($res); // inside function echo json_encode ($res); // not inside function Do you see the output from var_dump() in the response in browser dev console?
  15. You are writing that you want to sort results by artist. But in your sort selector you try to sort by help_roles. Is it help_roles, you want to sort by? Or is it that you want to filter results by help_role "artist"? Please clarify.
  16. If I understand correctly, you want to publish all draft versions of pages with a single click? For drafts you are using ProDrafts module? You might want to ask Pro module related questions in the dedicated VIP support forum.
  17. Hello and welcome to the forum! In PW you can override core modules by copying them from wire/modules to site/modules. If you have multiple copies of a module installed, you can go to Modules->Configure->AdminThemeUikit and choose there which copy to use. If you don't have this choice in the Module Edit Screen, follow these instructions: Copy wire/modules/AdminTheme/AdminThemeUikit to site/modules/AdminThemeUikit and then in the backend main menu do a Modules->Refresh, you will get a notification that AdminThemeUikit has multiple files installed in different locations and it lets you choose which file location to load the module from. You can do this and choose the files in wire/modules/AdminTheme/AdminThemeUikit. After that you can delete the site/modules/AdminThemeUikit folder and the warning should be gone.
  18. just to make sure, did you copy/paste this from your code? There is a typo "Imput", note the "m". It should read "getModuleConfigInputfields" To retrieve module config data from anywhere you can also use https://processwire.com/api/ref/modules/get-config/
  19. Here you are referring to ProcessModules. These provide custom pages in the admin. For an example see https://processwire.com/modules/process-hello/ and I also can strongly recommend the excellent blog post about ProcessModules linked by @BillH This is correct. You can read all about module configuration at https://processwire.com/blog/posts/new-module-configuration-options/ with examples both for the "old" and "new" way to implement your custom configuration fields. There is no settings button on the module's detail page. Once you have implemented input fields for module configuration, they will appear underneat the module information. All configurable modules are also listed in the admin menu under Modules->Configure When you are new to module development, the available classes can be quite confusing. But once you try and build a module yourself everything will get clearer. If you want to build custom pages in the admin, use a process module (https://processwire.com/modules/process-hello/). If you want to add general functionality, use a "normal" module (https://processwire.com/modules/helloworld/). This is because the API docs are auto-generated from the PW code. Since ConfigurableModule is an interface and not a class, the documentation for it is not being picked up by the script that generates the docs. But you have the path to the file in the core that defines the interface and there you have extensive documentation https://github.com/processwire/processwire/blob/master/wire/core/ConfigurableModule.php
  20. Great that this is working for you. Please share your additions to make it work with pageFileSecure. I never used that but would be interested in seeing how you implemented it.
  21. DOn't think this will make a big difference. Browsers will still handle it inconsistently.
  22. There is no built-in way ATM. But you can find some nice implementations here:
  23. To get more control over what happens in the user's browser, you can output your PDFs through a specific template file. Example implementation: Create a new template "pdf", in the URLs tab allow URL Segments Create a hidden page named "pdf" under home with that template. URL for that page will be: "/pdf/" Change text links for the PDFs to a format like "/pdf/{$pageId}/name-of-pdf-file.pdf" Sample code to create text links: /** @var Page $page page that the PDF file lives on */ /** @var Page $pdfPage page that ouputs the PDF file */ $pdfPage = $pages->get('template=pdf'); /** @var PageFile $pageFile object that holds the PDF */ $link = $pdfPage . $page->id . '/' . $pageFile->basename; // example result: /pdf/1234/name-of-pdf-file.pdf Now in site/templates/pdf.php you can use URL segments logic to retrieve and output the pdf if ($input->urlSegment1 && $input->urlSegment2) { $pageId = $sanitizer->int($input->urlSegment1); $baseName = $sanitizer->filename($input->urlSegment2); /** @var PageFile $pageFile object that holds the PDF */ $pageFile = $pages->get($pageId)->file_field->getFile($baseName); if ($pageFile) { $filePath = $pageFile->filename; // see https://processwire.com/api/ref/wire-file-tools/send/ for more options /** @var Files $files PW Files API */ if($filePath) $files->send($filePath, array('forceDownload' => false)); } } Instead of sending the file directly to the browser, in pdf.php you could implement https://pdfobject.com/ to embed it for every browser
  24. What code are you using to display the PDF / send the PDF to the browser, are you using $files->send()? With that method you have control over the headers. Firefox uses Mozilla's PDF.js for PDF display. If you want to have a consistent display of PDFs across browsers you might want to consider implementing it on your site. This might of interest: And this: https://pdfobject.com/
  25. You can use the User::changed hook to do what you want (see https://processwire.com/api/ref/wire/changed/). Put this in site/ready.php: $wire->addHookAfter('User::changed', function ($event) { if($event->arguments(0) === 'pass') { $user = $event->object; $this->wire->log->save('password-changes', "User $user->name has changed their password"); } }); Now everytime a user changes their password, it will be logged to Setup->logs->password-changes. You can do similar thing with roles if($event->arguments(0) === 'roles') { $user = $event->object; $oldRoles = $event->arguments(1); $newRoles = $event->arguments(2); // code to compare $oldRoles/$newRoles // write to log } If you want to have that information in the session log, just do $this->wire->log->save('session',...)
×
×
  • Create New...