-
Posts
1,419 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Juergen
-
Hello @kongondo only a question: is it possible to use a special field of a page for the field of the matrix (fe a date field, an integer field,..)?
-
Cannot install the module There is always the message that FieldtypRepeaterMatrix is not the correct version, but I have downloaded it today from the modules directory - so it must be ok.
-
Here is a new created version to track changes which works without any problems and you dont have to take care about the deletion of input values if the page was not saved successfully (like in the version before) Put this little piece of code inside your ready.php. //Compare before and after values and output a warning message $pages->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments('page'); $page->of(false); //configuration: change it to your needs $templates = ['event_businessvacations', 'event_dates', 'event_events', 'event_specialbusinesshours']; //array of templates where this hook should run $fields = ['summary', 'body']; //array of fields which should be checked //configuration end if(in_array($page->template->name, $templates)){ $changedfields = []; foreach($fields as $fieldname){ if ($page->isChanged($fieldname)) { // Page as it is in the DB $oldPage = wire('pages')->getById($page->id, array( 'cache' => false, // don't let it write to cache 'getFromCache' => false, // don't let it read from cache 'getOne' => true, // return a Page instead of a PageArray )); $changedfields[] = $oldPage->fields->$fieldname->label; } } $changedfields = implode(", ", $changedfields); if(!empty($changedfields)){ $this->warning(__("The following fields have been changed: {$changedfields}")); } } }); Change the configuration block to your needs (template names, field names). This little code snippet outputs only a warning message which fields have been changed - not more or less, but you can also run some other logics - its up to you. Note: Works also with repeaterfields, but you can only check the repeaterfields for changes in general. It is not possible to check for specific fields inside the repeater.
- 2 replies
-
- 10
-
-
-
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?
-
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
Thanks I am always glad to read about optimizations! -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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? -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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 -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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. -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
Yes I have done it with switch/case outside of the foreach - this was a part from the old code. -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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!!!!!! -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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. -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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. -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
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 -
How to output wire message after running a hook problem
Juergen replied to Juergen's topic in API & Templates
Could be the problem. Thanks for confirming the correctness of the code, so I can focus on finding the problem. -
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
-
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!!
-
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
-
Works now! Thank you.
-
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
-
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
-
how do I add site navigation if starting on the blank template?
Juergen replied to Simon Love's topic in Getting Started
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. -
Getting tab label in different languages on frontend fails
Juergen replied to Juergen's topic in API & Templates
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,....