-
Posts
1,423 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Juergen
-
Both possible solutions dont work $page = $event->object->hasPage; or $pages->addHookBefore('Inputfield::render', function($event) instead of $this->pages->addHookBefore('Inputfield::render', function($event) $page is always empty
-
Hello, I have written a hook to disable an inputfield on certain conditions: //Disable createevents field if there are no children $this->pages->addHookBefore('Inputfield::render', function($event) { $page = $event->arguments(0); $field = $event->object; if(in_array($page->template->name, array('event_businessvacations','event_specialbusinesshours','event_dates','event_events'))) { if(count($page->children) == 0){ if('createevents' === $field->name ){ $field->attr("disabled" , "disabled"); } } } }); I am getting always following notice from Tracy: PHP Notice: Trying to get property of non-object in /home/.sites/24/site1275/web/site/ready.php:310 This is the line where $page is defined. How can I grab $page in this case correctly or do I have to use another type of Hook?
-
Ideas and best practices to secure a member registration system
Juergen replied to modifiedcontent's topic in Security
Hello @modifiedcontent Composer safes you a lot of time on updating and installing PHP-libraries which you want to use in your project. I use more than 1 external PHP library on my projects, so it makes really sense in my case. Honeypot class is only one of them. If you have time you could read how to install it on your system. It seems to be difficult at the beginning, but there are also tutorial videos on Youtube that are really good and easy to follow. The only thing to mention: you have to work with the CLI (command line interface). If you want to install for example the Honeypot class you only have to write composer require dominiquevienne/honeypot into your CLI and if you want to update it later you only have to write composer update Thats all and the latest version will be installed. No need to look for updates manually. No need to install updates manually. So its a really useful solution to install libraries and keep them up to date with less work.- 10 replies
-
- 1
-
-
- no subscription detected
- not recognized
-
(and 4 more)
Tagged with:
-
How to store translateable value in multilanguage textfield via API
Juergen replied to Juergen's topic in General Support
Thanks for your tipps. I will try it via the Hook method. -
How to store translateable value in multilanguage textfield via API
Juergen replied to Juergen's topic in General Support
Thanks @BitPoet, the reason for this is because I want to show additional event info inside the page tree next to each event. So if the event has a specific start and end time, the times will be shown next to the date. If the event is all day long, the text "all day long" (in German ganztägig) will be displayed. Therefore I have created a simple textfield (name: eventpagetree) in which the corresponding value will be added via a Hook. On the template side I create the pagetree values like this: That was the idea behind this. -
Hello @ all, I am struggeling by storing a translateable string into multilanguage textfield via the API. This is the translateable string: __("all day long") I want to store this into the multilanguage textfield, but it doesnt work as expected. This is what I have so far: foreach ($this->languages as $lang) { $langtype = $lang->get('name'); $page->eventpagetree->setLanguageValue($langtype, __("all day long")); } But this stores always the same value in both languages. The name of the multilanguage textfield is "eventpagetree" in this case. Can someone give me a hint or a working solution?
-
Yeah, now I see it!
-
Thanks for your efforts. No need to hassle!
-
I have sent you a PM.
-
Ok I have commented it out if (!$dir->isDir() /*&& strpos($path, '/.')*/ === false && preg_match($fileNamePattern, $path) && !in_array(basename($path), $excludeFilenames) ) { but no effect
-
Ok clearing the cache doesnt have any impact on the behaviour.
-
-
I have a lot of hooks inside ready.php, which will be loaded with every page load - so there are a lot of
-
Other toggles from other panels work as expeceted. I am running Tracy in Backend at the moment, so no conflict with frontend scripts. Only to mention: My Antivir software from Kaspersky adds a JS-File inside the head section of the page. Maybe this could be a reason.
-
I am using the latest Firefox but I have also tested it with IE - same result. Browser console doesnt show any errors.
-
Another question: in the panel there is the button "toggle all", but nothing happens if i click on it.
-
Ok, i figured it out. Adding $paths = array(); before the foreach start solves the problem. So it seems that if $path is not defined as an array before the foreach, it doesnt work. So the complete code is like this: $paths = array();//this solves the problem foreach ($iter as $path => $dir) { // '/.' check is for site module backups - SKIP_DOTS above is not excluding these if (!$dir->isDir() && strpos($path, '/.') === false && preg_match($fileNamePattern, $path) && !in_array(basename($path), $excludeFilenames) ) { $paths[] = $path; } } return $paths; Best regards
-
I am running PHP 7.0.22 so "[]" are not the problem.
-
Hello, today I have activated the Captain Hook Panel in Tracy for the first time and I always get this message: What should I do to prevent this? Where can I define the variable "paths"? Best regards
-
Hello, I have a hook which should copy the value of one field to another on special type of templates: $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments(0); $page->setOutputFormatting(false); if(in_array($page->template->name, array('event_specialbusinesshours', 'single-special-business-hours'))) { $page->endeventdate = $page->starteventdate; } }); The field value will be copied -> this works. The 2 fields are requiered. After pressing the save button I got the following message that the value is missing, but it is still there To eliminate this error I could set the second field to not required, but I want an explanation why a copied value with "hook before saveready" leads to such an error-message. Does the validation take place before this hook. If yes, which hook method should be used instead? Best regards
-
So I ended up with the slightly modificated code of abdus which works like a charme: wire()->addHookAfter('ProcessPageAdd::buildForm', function (HookEvent $e) { /** @var InputfieldForm $form */ $form = $e->return; $form->add([ 'type' => 'markup', 'value' => '<script> $("#template").prepend("<option value=0 selected>Please select</option>"); </script>' ]); $template = $form->getChildByName('template'); $template->attr('required', 1); }); Before pressing the save button: After pressing the save button an nothing was choosen:
-
Hello @abdus your code works, but it doesn´t solve my problem. I have the template selection not in my page template because I don´t want to allow the user to change the template. The selection has to be taken before the new page is created. This is necessary because there are different UIs (forms) for the different type of templates. This is the place where the user have to select the template type: At the top the user has to select the prefered template type depending on which kind of page he wants to create (Business vacation, Event, Default date or Special openinghours). Depending on this selection the corresponding input form will be loaded. The problem: There is always one template type selected and no user action needs to be taken, but I want to force the user to select the type on his own - so he has to consider what kind of event he wants to create. So instead of a pre-selected template type I want an option like "make a choice" so the user has to select one. My idea was to add another template called "make a choice" which appear on the first place and has no function. Afterwards I make a custom validation via a hook. If this template selection was not changed to another template type the user gets an error messages to select a template type. But maybe there will be another more simple solution.
-
Thanks for the quick response. I have tried this before but it doesnt seem to work. This was because I had a writing mistake in my code. Now it works