Jump to content

Juergen

Members
  • Posts

    1,413
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Juergen

  1. Hello @ all, I have a required field inside a template and I want to add a value via a hook if the user enters nothing in this field. Therefore I have tried to hook before "processInput". $wire->addHookBefore("InputfieldDatetime::processInput", function($event) { $page= $this->process->getPage(); $page->of(false); if(!in_array($page->template->name, ['single-event'])) return; if($page->parent->reservationdeadline != ''){ $diff = ($page->parent->starteventdate) - ($page->parent->reservationdeadline); if(($page->starteventdate) && ($page->reservationdeadline != '')){ $page->reservationdeadline = ($page->starteventdate)-$diff; } } }); So if the user presses the save button, then it should be checked if a value was entered in date field called "reservationdeadline". If not then a value should be entered via the hook before the validation of the required field takes place. At the moment I always get the error message that there is no value entered in the required field. Could someone give me a hint how to achive this? I know I could set the option to non required and enter the value always if nothing is there but it is possible to change it before the form will be validated?
  2. Thanks I am always glad to read about optimizations!
  3. Oh I understand! I only check after starting the hook if it is the right template and then make some manipulations. So it would be better to check before starting the hook if it is the right template. Thats the current case: $pages->addHookAfter('saveReady', function($event) { $page = $event->arguments(0); $page->of(false); $pages = wire('pages'); $name = $page->template->name; if(in_array($page->template->name, ['event_businessvacations', 'event_dates', 'event_events', 'event_specialbusinesshours'])){ ........ } }); But this would prevent the hook to be triggered on every page: $pageid = $input->get('id'); if(in_array(wire('pages')->get($pageid)->template->name, ['event_businessvacations', 'event_dates', 'event_events', 'event_specialbusinesshours'])){ $pages->addHookAfter('saveReady', function($event) { $page = $event->arguments(0); $page->of(false); $pages = wire('pages'); $name = $page->template->name; ........ }); } Is that what you mean?
  4. I dont know what you mean with endless recursion. The pages will created from an array with dates (fe an array with 10 dates). So 10 child pages will be created. There is a hard limit of 732 pages that can be created (limited by the RRULE library I use to get the recurrences of dates). Ah you mean recursion functions - translation problem. By the way: latest DEV and PHP 7
  5. In my case they dont work if I use special characters. I have also tested it with and without special characters and nothing will be shown if I use "ü", but if I replace the "ü" with "ue" everything works as expected. I also have replaced the hard coded message text with translateable text, so there are no German Umlauts present any more. But this is really a strange thing. The main problem is that I dont get any information from the log files or from Tracy, so it was a trial and error experiment. I removed always a little part of the code to check where the problem could be. This leads me to this cause.
  6. Yes I have done it with switch/case outside of the foreach - this was a part from the old code.
  7. OK, here is the final solution for this problem: Dont use German Umlauts (ä,ü,ö) inside your message texts. It prevents the message from appearing. Maybe this could be also the case with other special characters (fe ß) - but not tested. This doesnt work: $this->message("Überraschung"); but this works: $this->message("Ueberraschung"); A little mistake but really hard to find. So keep an eye to only use default letters in message texts!!!!!!
  8. Ok, I have traced down the problem once more and it seems that the creation and saving of child pages inside the hook function is responsible for this behaviour. If I comment out the creation of the child pages the messages appear: foreach($eventdatesarray as $eventdate){ if($page->template == 'event_businessvacations'){ $itemtemplate = 'single-business-vacation'; } if($page->template == 'event_dates'){ $itemtemplate = 'single-date'; } if($page->template == 'event_events'){ $itemtemplate = 'single-event'; } if($page->template == 'event_specialbusinesshours'){ $itemtemplate = 'single-special-business-hours'; } $k = new Page(); $k->of(false); $k->parent = wire('pages')->get($page->id); $k->template = $itemtemplate; // set template ......... ......... $k->save(); //especially the saving seems to make problems with messages } Does anyone have the same problem? The hook itself works and the child pages will be created, only the messages dont appear.
  9. No I have got no errors, wheter in PW logs neither in Tracy. But now the problem is back and it seems there is an interference with other hooks. The problem is that the hooks works well, but the messages still dont appear and I havent find a way to check where the problem comes from. Could the problem occur if you are running the same hook type multiple times ? In my case I have a lot of "addHookAfter('saveReady'...) hooks running.
  10. Ok I found the mistake: There was a missing $child->of(false); before saving values to a child page in a foreach loop and this causes the messages to not appear. So keep an eye to always include the command for unformatted values before storing something in the DB if you save!! Otherwise tracing the problem to its source will take a lot of time
  11. Could be the problem. Thanks for confirming the correctness of the code, so I can focus on finding the problem.
  12. Hello @ all, I am running a lot of hooks which are located inside the ready.php. Now I want to output some info to the user after a hook function took place in form of a message in a backend. Just to clearify: $pages->addHookAfter('saveReady', function($event) { //here comes the logic $this->message('test'); }); I want to output fe a message that a specific action (the creation of events) took place, but nothing happens. I have done this in the past in the same way with success, but now nothing works (I use the latest dev) What is wrong with this piece of code? Thanks
  13. Hello Adrian, just to clearify: the empty labels problem happens after upgrading to the version with the option of hiding the labels (I think version 2.0.10) not from version 1 to version 2 (major upgrade). Thanks for the fast fix!!
  14. Hello Adrian, could you please check the following: After updating the module all my labels of the different input fields (area code and so on) with the translations are gone. I had to enter it once more. It seems that updating the module deletes all entered label values. Thanks PS: The only message I got from Tracy was the following: PHP Notice: Undefined offset: 3 in .../site/modules/FieldtypePhone/FieldtypePhone.module:322
  15. Works now! Thank you.
  16. Hello Adrian, thanks for the great update! In my case it seems that the field description and notes will not be outputted in the backend. Can someone confirm this behavior? Best regards
  17. Can you compare my settings to yours, because in my case it works well. I have my JS custom file located in the folder "ckeditor". Path to the JS-file entered in the input: mystyles:/site/templates/ckeditor/mystyles.js and in the mystyles.js I have fe UIKit styles like these: CKEDITOR.stylesSet.add( 'mystyles', [ { name: 'Inline Code', element: 'code' }, { name: 'Inline Quotation', element: 'q' }, { name: 'Bild links', element: 'img', attributes: { 'class': 'align_left' } }, { name: 'Bild rechts', element: 'img', attributes: { 'class': 'align_right' } }, { name: 'Bild zentriert', element: 'img', attributes: { 'class': 'align_center' } }, { name: 'Small', element: 'small' }, { name: 'Text durchstreichen', element: 'del' }, { name: 'Inserted Text', element: 'ins' }, { name: 'Cited Work', element: 'cite' }, { name: 'Highlight', element: 'mark' }, { name: 'Einfügen', element: 'ins' }, { name: 'Sample', element: 'samp' }, /* Uikit headlines */ { name: 'unterstrichen', element: 'h3', attributes: { 'class': 'uk-heading-divider' } }, { name: 'Linie in der Mitte', element: 'h', attributes: { 'class': 'uk-heading-line' } }, { name: 'Kugel am Anfang', element: 'h', attributes: { 'class': 'uk-heading-bullet' } }, /* Uikit paragraphs */ { name: 'Kleine Schrift', element: 'p', attributes: { 'class': 'uk-text-small' } }, { name: 'Große Schrift', element: 'p', attributes: { 'class': 'uk-text-large' } }, { name: 'Nur Kleinbuchstaben', element: 'p', attributes: { 'class': 'uk-text-lowercase' } }, { name: 'Nur Großbuchstaben', element: 'p', attributes: { 'class': 'uk-text-uppercase' } }, { name: 'Erster Buchstabe groß', element: 'p', attributes: { 'class': 'uk-text-capitalize' } }, { name: 'Farbe: gedämpft', element: 'p', attributes: { 'class': 'uk-text-muted' } }, { name: 'Farbe: Primär', element: 'p', attributes: { 'class': 'uk-text-primary' } }, { name: 'Farbe: Erfolg', element: 'p', attributes: { 'class': 'uk-text-success' } }, { name: 'Farbe: Warnung', element: 'p', attributes: { 'class': 'uk-text-warning' } }, { name: 'Farbe: Gefahr', element: 'p', attributes: { 'class': 'uk-text-danger' } }, /* ul classes */ { name: 'Liste mit Kugel', element: 'ul', attributes: { 'class': 'uk-list uk-list-bullet'}}, { name: 'Liste mit Linie', element: 'ul', attributes: { 'class': 'uk-list uk-list-divide'}} ] ); Here is a screen shot of the custom styles dropdown: So in my case I didnt find it difficult to add styles
  18. If you want a navigation different from the page tree you can write it also in HTML and add it to the template. Theres no need to use a function to create it. You can get the URL for a page in this way: $url = $pages->get(Id of the page)->url; fe. if the page has the id 45 you get the url like this: $url = $pages->get(45)->url; You can use it to write the menu in HTML and add the URLs with PHP like this <a href="<?php $pages->get(45)->url;?>"><?php $pages->get(45)->title;?></a> This outputs the link and as linktext the title of the page. There are many ways to create a navigation. I recommend you to take a look at the cheatsheet.
  19. Ok, I ended up with the following codes in site/_init.php //get labels, title, values and descriptions in different languages if ($user->language->name != 'default') { $title = "title{$user->language}"; $value = "value{$user->language}"; $label = "label{$user->language}"; $description = "description{$user->language}"; $notes = "notes{$user->language}"; } else { $title = 'title'; $value = 'value'; $label = 'label'; $description = 'description'; $notes = 'notes'; } and on the page itself: echo $page->template->fields->getFieldContext('tab1')->$label; Pay attention to "$label" instead of "label". The same can be achived by using description, notes,....
  20. I use the latest DEV and PHP 7. Just to clearify: My tab field is type of "FieldsetTabOpen".
  21. Strange, in my case it outputs nothing with the same code and Tracy doesnt complain about anything.
  22. Sorry this was only a writing mistake. In the original code the comma is present.
  23. Hello @all, I have tried to output the overridden label from a specific tab inside my template on the frontend. I have used this documentation: https://processwire.com/api/ref/template/get-tab-label/ The tab name is called "tab1" and the labels were overriden with "Kontakt" (German) and "Contact" (English). To output the label depending on the language on the frontend I use the following code snippet: $tablabel = $page->template->getTabLabel('tab1'); echo $tablabel; and $tablabel = $page->template->getTabLabel('tab1', $user->language->id); echo $tablabel; But both versions output only the default (German) tab label. I appreciate your help. Is there something that I am missing? But both version output an empty string, so it seems that the overridden values will not be taken into account.
  24. Its a shared host. It says true. For the moment I have disabled this module because the loading time of the page increases significantly.
  25. @flydev It means "The waiting time for the connection has expired"
×
×
  • Create New...