• Content count

  • Joined

  • Last visited

  • Days Won


Juergen last won the day on November 5 2017

Juergen had the most liked content!

Community Reputation

387 Excellent

About Juergen

  • Rank
    Hero Member

Profile Information

  • Gender
  • Location
  • Interests
    Playing electric guitar (Rock, Heavy), flying model helicopters

Recent Profile Visitors

4,456 profile views
  1. Great! I didnt know that this exist
  2. In my case I want to count the children which are under the current page beeing edited. Each child page is a date, so I count of how many dates this page has. But counting the children via siblings could also be an opportunity.
  3. Here is my code for others who also deals with the same issue. This little function prevents the deletion of the last child page if page has a certain template. Code runs inside ready.php. //prevent deletion of last child function wire()->addHookBefore('Pages::trash', null, 'preventdeletionlastevent'); wire()->addHookBefore('Pages::delete', null, 'preventdeletionlastevent'); function preventdeletionlastevent($event) { $page = $event->arguments(0); if(!in_array($page->template->name, ['single-date', 'single-event', 'single-business-vacation', 'single-special-business-hours'])) return; $parent = $page->parent; $childrennumber = count($page->parent->children); if($childrennumber === 1) { $event->replace = true; // now original function won't be called $event->return = wire()->warning(__("Deleting of the last date is not allowed. There must be at least 1 date.")); } else { wire()->message(__("1 date was deleted.")); } }
  4. Aaahh, I see!! This would be a solution Thanks!!!
  5. Thanks @Zeka, but I guess in this case I have to define the functions for each "Class::method" - so I have also 2 functions ("Pages::trash", "Pages::delete") - so I can leave the 2 hooks as they are.
  6. Hello @ all, In my case I have some hooks with the same code which run on page "Pages::trash" and "Pages::delete" inside may ready.php. For the moment I have used separate hooks for each of them. Is there a possibility to combine them so the same code runs only once and includes "trash" and "delete"? Explanation: Instead of $wire->addHookBefore("Pages::trash", function($event) { .... run code }); and $wire->addHookBefore("Pages::delete", function($event) { .... run code }); combine them $wire->addHookBefore("Pages::trash","Pages::delete", function($event) { .... run code }); This would be more efficiently for further changes and reduces the code. Best regards
  7. Hello @kongondo, I have discovered a strange behavior: I use a pagetable field inside a parent page. If click on the link inside the pagetable to open a child page inside a modal, I will be logged out from the system if the child page has a matrix field inside. I have traced down the problem and it has to do with a hook that I run on the pagetable field of the parent page (inside my ready.php): $wire->addHookBefore('InputfieldPageTable::render', function($event) { if($this->process != 'ProcessPageEdit') return; $table = $event->object; $page = $this->process->getPage(); // event table if(in_array($table->name, ['datespagetable', 'specialbusinesshourstable', 'eventspagetable', 'businessvacationpagetable'])) { if(count($page->children) == 0){ $table->notes = ""; $this->buttonHook = $this->addHookAfter("InputfieldButton::render", null, function(HookEvent $event){ $event->return = __("Here all dates will be shown afterwards if some were created."); }); } //this part of the button hook is responsible for loggin me out if I click on the link to the page inside the pagetable else { $this->addHookBefore("InputfieldButton::render", null, function(HookEvent $event){ $button = $event->object; if($button->name == 'button'){ $button->attr('value', __('Add event')); } }); } } }); Inside this hook there is another hook for rendering the "Add new" button. So this "InputfieldButton::render" hook is responsible for loggin me out (if I remove this part everthing is fine). So its not a big problem for me (I have comment it out), but maybe you have an idea, why these lines of code could lead to this behavior in combination with the matrix field. Best regards
  8. Oh, sorry - my fault. I use the 2D repeater matrix from Kongondo.
  9. 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,..)?
  10. 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.
  11. 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.
  12. Only to mention: after page save was not an opportunity for me, because the validation of the required field kicks in before this hook . I have tried it before, but thanks for your hints @Zeka
  13. I make the field non required - it is the most simple way
  14. Ok, I thought that the form data could be changed before processing the form if I use "$wire->addHookBefore("InputfieldDatetime::processInput", function($event) {" Thanks @BitPoet
  15. 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?