torf
Members-
Posts
78 -
Joined
-
Last visited
Everything posted by torf
-
Ok. I figured it out, but that was a tough one. Processwire adds languages to image description in a very unexpected way to say the least. If you have two languages the image array has three possibilities: 1.both languages description are filled. ( [description1031] => Description for LanguageID 1031 [description] => Description for main Language ) 2. only the secondary language is filled: ( [description1031] => Description for LanguageID 1031 [description] => ) 3. only the main language is filled: ( [description1031] => Description for main Language [description] => Description for main Language ) So in the third case an fallback is created which automatically fills the secondary language with the main language description field if empty. Neat if you want to show the main language if no description exists but not so handy if it is supposed to stay empty. The only way I found to bypass that behaviour is a quite bumpy function, but at least it works: function getLocalizedDescription($image, $user) { $lang = $user->language; // Safely get all available keys as an array $imageData = $image->getArray(); $descDefault = $imageData['description'] ?? ''; if ($lang->isDefault()) { return trim($descDefault); } $descKey = 'description' . $lang->id; $descTranslated = $imageData[$descKey] ?? null; // Only return translated description if it's truly set and different if ($descTranslated !== null && trim($descTranslated) !== '' && trim($descTranslated) !== trim($descDefault)) { return trim($descTranslated); } return ''; }
-
I've setup a multi language site where the default behaviour is to not show a field if there is no translation available. For normal fields like text or textarea there is an option under "details" how to address empty translations. But I also use image descriptions, and there this option is missing. So the image description always shows the main language, if there is no secondary. Does anyone know how to avoid that?
-
@MSP01 Thanks - that's an interesting approach, but it's too late for this time - I'd have to rewrite half of the templates. @Robin S That worked. It's still a bit of coding, since in my case it's more then a dozen templates, but it works. Changed the last line to make it a bit easier when working on numerous parent templates: $arr_of_templates = ["parent_1","parent_2","parent_3"]; // and so on if((in_array($page->template, $arr_of_templates)) && ($user->hasRole('editor'))) $event->return = false; Thank you very much
-
I know this topic has been addressed several times before, but has anyone a solution in 2025? As for my site manual sorting of the child pages is crucial for some users, but they are not supposed to touch the parent page. Can I achieve this somehow? Thanks Torf
-
Ah. Thanks a lot - It's a bit more complicated then I thought, but this will work.
-
Thanks - that indeed works, but removes all the values from the field. In my case I'd need to keep the other values and just delete a specific on. But I'll keep that in mind as plan B if I do not find another solution.
-
Hello, I'm trying to add or remove a value from a read only page reference field based on the fact if an image field on the same page is empty or not. The other values should not be affected. So in my ready.php I have: $wire->addHookBefore('Pages::saveReady', function($event){ $page = $event->arguments(0); if($page->hasField("images")) { if($page->images->count() > 0) { $page->my_page_reference_field = 'Title of referenced Page'; //-> this works and adds the value to the list $this->message("Added value"); } else { $page->my_page_reference_field->remove('Title of referenced Page'); //-> this doesn't $this->message("Value removed"); } } }); Adding the Value works great, but I cannot figure out how to remove a specific value. Does anybody know how to solve this?
-
Hi, I've got a Page Reference Field in my Backend, to choose multiple options from a list. Now my Frontend retrieves the data and some additonal graphics from those pages in the order it has been chosen in the backend. foreach($my_page_data->my_text_tag_field as $item) { echo "url({$item->graphic->url()}), "; } But as those graphics are layered in my frontend, I always need them in the order they are listed in my backend. $my_page_data->my_text_tag_field->sort() Just gives me an error. Does anybody know how to sort the data in frontend so that it matches the sorting order in the backend page list, not the sorting order in the page reference field? Thanks a lot
-
Ok. I found the problem. Just in case anyone runs into the same thing: I had an included .php file that was was loaded on the very beginning of my template. That file was coded in ANSI which caused the language string detection to break. Another ANSI coded include at the end of the template did not do any harm btw.
-
I have a strange behaviour that I do not understand fully. I have a couple of translatable strings in my template file: $Headline_1 = __("Headline1"); $Headline_2 = __("Headline2"); So when I click on "Find files to translate" this template is found, but only the first string is presented as translatable. If I change the line to $Headline_1 = __("Headline1"); //Test $Headline_2 = __("Headline2"); //Test Processwire also detects only the first string, but puts the rest of the code as comment. So obviously the system does not detect the line breaks. The file is in UTF without BOM, and had only CR as linebreaks. But changing them to CR/LF did not do anything. Did anyone ever encounter something like this, or can tell me where I overlook something crucial?
-
For the records: I found a way to use multiple points or areas directly from a repeater, but it's not the most beautiful method. It works by simply omitting the frontend part of the module. I just load the leaflet js and css manually, extract the lat and lng from the repeater, and paste them in the site. Which has the advantage that I can use additional fields in my repeater (in my example I use a field named "radius" to draw multiple circles: <div id="map" style="height: 200px"></div> <script> var map = L.map('map').setView([51.505, -0.09], 13); L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map); let boundaries = []; <?php foreach($page->my_repeater as $repeaterdata) { $diameter = $repeaterdata->radius * 1000; echo " var circle = L.circle([{$repeaterdata->map->lat}, {$repeaterdata->map->lng}], { color: 'red', fillColor: '#f03', fillOpacity: 0.5, radius: {$diameter} }).addTo(map); "; } ?> </script> Please note that this is just a proof of concept. I haven't played around with markerclusters, automatic boundaries or any other fancy stuff at this point.
-
Thanks a lot @Cybermano That worked flawless.
-
Thanks @Cybermano I already did it with page arrays and it works great, but this time I'd prefer a repeater. Using page arrays would make the backend to complicated.
-
Hi, does anybody know how to use the module with a repeater? I need to have multiple mappoints in one map at my frontend, and due to the nature of the site I cannot put them in pages. So I thought of using a repeater for those points (as it is not possible to add multiple markers to one map). In the backend it works fine, but I cannot figure out how to collect those points and display them in one map. <?php $map = $modules->get('MarkupLeafletMap'); echo $map->getLeafletMapHeaderLines(); $mappoints = []; foreach ($page->map_repeater as $point) { array_push($mappoints, $point->map); //or array_push($mappoints, [$point->map]); //or array_push($mappoints, $point->map->LeafletMapMarker); array_push($mappoints, [$point->map->lat, $point->map->lng]); } echo $map->render($page, $mappoints, array('height' => '270px')); ?> All I tried gave me different mistakes. Does anybody know the correct syntax?
-
So after going through the database for days without finding any suspicious entries I had a long talk with my client and it turns out - the error wasn't there in the beginning. So @flydev: duplicator is definitely innocent. The error was a simple typo in production ready.php (they are both quite different so it wasn't too obvious). I had two lines with: if(($page->template = "myTemplate") But why this altered the output the way it did I have no idea.
-
@flydev I'll start with 8 and see where it get's me tomorrow. ? @WillyC I'll give it a try but first I have to bring the whole darn thing back to my dev Server. disabling the mods on production is something I wouldn't dare to. No idea if they may loose some settings and both are crucial for the site.
-
OPening page 3 works directly. But when I try to access another tab I get the next warning about templates. Funny thing - this time the Problem is on page 8. And the same page on my dev site: I've tried with advanced mode and it looks just as it's supposed to look. But you are right. I do not use multi-language (only a german translation) but a couple of modules that do fiddle around with user rights ( Admin Restrict Branch and Page Edit Per User). But those modules are on both sites.
-
So far I found no strange differences. But that will take some time as the pages are quite different regarding their content. ProcessWire Version is 3.0.184 What I found in my exeptions Protocol is: Template changes are disallowed on page 3 because it has system statusIn /wire/core/Page.php line 2000 And thats the setTemplate function protected function setTemplate($tpl) { if(!is_object($tpl)) $tpl = $this->wire()->templates->get($tpl); if(!$tpl instanceof Template) throw new WireException("Invalid value sent to Page::setTemplate"); if($this->template && $this->template->id != $tpl->id && $this->isLoaded) { if($this->settings['status'] & Page::statusSystem) { throw new WireException("Template changes are disallowed on page $this->id because it has system status"); } if(is_null($this->templatePrevious)) $this->templatePrevious = $this->template; $this->trackChange('template', $this->template, $tpl); } if($tpl->sortfield) $this->settings['sortfield'] = $tpl->sortfield; $this->template = $tpl; return $this; } But I've absolutely no idea why Processwire would try to set a template when opening the admin branch of the site tree.
-
Thanks for the reply. Both are MyIASM, but what I found is that dev is utf8 while production utf8mb3. No idea if that makes any difference. Doing another export is no option as the production site has hundreds of articles (it's up and running already), but I'll go through it manually.
-
Database is libmysql - mysqlnd 7.4.33, Server Version: 10.6.11-MariaDB, Server runs on cp1252 West European, DB is utf8mb4_unicode_ci Unfortunately there is no direct phpmyAdmin access without sending my clients admin access to the whole Domain/hosting.
-
Thanks a lot - I used Version v1.4.21 But the sites are not 100% the same. There is the possibility that something has been changed on production server, or that some read/write access may be different.
-
I've got a strange behaviour on one site I cannot explain. It looks like my superuser is missing some rights and I cannot find out where i could have compromised the system. - I cannot add any page directly under my root page - if I click on admin pages i get a strange warning (Page 3 is supposedly Admin/Pages) After that I cannot open the page lister. It stays empty and giving me an error with the same text. If I log out sometimes it helps, sometimes it stays that way for some time. - All of my users (including superuser) are missing the "view"button in page lister I tried to add a new superuser, but that makes no difference. Also I've got the same site in my development server where I have no odd behaviour. Has anybody experienced something like that before? (The Site has been moved via Duplicator - maybe that has changed something?)
-
Oh! I just did not realize that one. Thanks a lot!
-
I have no idea if that is even possible, but I run into a problem with planning ahead the structure every now and then: If I have multiple templates that use the same field I try to reuse my fields of course. So let's say I have the field: myPictures (Images / jpg / max 5 images / ...). I use that field with different descriptions in multiple Templates. Now the site is in use, and after some month the client decides that in one template there need to be 8 possible upload slots with only png allowed. Now I'm stuck. If I change the field it changes for all, if I make a new field I loose all the uploads that already have been made for this template, if I'm going the safe way and add different fields for every template from the beginning I get to many fields that are maybe never needed. Is there any solution for that problem?
-
As i ran into the same Problem here is a very simple solution that only uses one loop for grouping (well it's not exactly grouping, but it looks like) $myPages = $pages->find("template=myTemplate, sort=FieldtoGroupby, sort=title"); //select all pages and sort by field you want to group, then by sorting field $lastgroup = "somevalueneverused"; foreach($myPages as $myPage) { $actualgroup = $myPage->FieldtoGroupby; if ($lastgroup != $actualgroup) { echo "<h3>".$myPage->FieldtoGroupby."</h3>"; } echo "<p>".$myPage->title."</p>"; $lastgroup = $actualgroup; } Downside: you only can sort your categories by the field to group by.