Jump to content

gebeer

Members
  • Posts

    1,386
  • Joined

  • Last visited

  • Days Won

    39

Everything posted by gebeer

  1. I am still investigating the strange behaviour of placing a var_dump() in the code preventing the error like I described in #11 Reading up on var_dump() in the PHP docs, I found this: In the foreach that loops through the page fields, why does resetting the internal pointer of the fields array make a difference and what can I change in my code to avoid the error in the first place?
  2. I managed to successfully change my default language Everything went quite smoothly, except for some strange errors that I desribed above and which might be related to my particular environment. Here my complete function for swapping a language with the default language. Instructions for necessary steps after swapping languages are included. <?php function swapLanguages($pages, $lang) { $startTime = microtime(true); $langDefault = "default"; $log = ["languages" => "Swap field values for language {$langDefault} with {$lang}", "pages" =>[]]; $languages = wire("languages"); // get languages $l1 = $languages->get($langDefault); $l2 = $languages->get($lang); foreach ($pages as $p) { $log["pages"][$p->id] = ""; $fieldlog = " name"; $p->of(false); // swap page names $nameDefault = $p->localName($l1); $name = $p->localName($l2); if($nameDefault != $name && !empty($name)) { $p->set("name",$name); $p->set("status$l2",1); $p->set("name$l2",$nameDefault); } elseif($nameDefault != $name && empty($name)) { $p->set("status$l2",1); $p->set("name$l2",$nameDefault); } // iterate through all fields and swap multi language field values foreach ($p->template->fieldgroup as $field) { if($field->type instanceof FieldtypePageTitleLanguage || $field->type instanceof FieldtypeTextareaLanguage || $field->type instanceof TextLanguage) { $fieldlog .= " {$field->name}"; // var_dump($p->$field); // needed this for some pages otherwise they threw an error // $p->of(false); // needed this for some pages otherwise they threw an error $langDefault = $p->$field->getLanguageValue($l1); $lang = $p->$field->getLanguageValue($l2); if( $langDefault != $lang && !empty($lang) && !empty($langDefault) ) { $p->$field->setLanguageValue($l1, $lang); $p->$field->setLanguageValue($l2, $langDefault); } elseif( $langDefault != $lang && empty($lang) ) { $p->$field->setLanguageValue($l2, $langDefault); } elseif( $langDefault != $lang && empty($langDefault) ) { // only needed this for pages that got created through API and had no default lang value set $p->$field->setLanguageValue($l1, $lang); } } } try { $p->save(); $log["pages"][$p->id] = "Swapped values in fields: {$fieldlog}"; } catch (Exception $e) { $log["pages"][$p->id] = 'Error: ' . $e->getMessage(); } $p->of(true); } // write logfile $logfile = fopen(wire("config")->paths->logs . "swaplanguage-log.txt", "w") or die("Unable to open file!"); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($log)); foreach($iterator as $key => $value) { fwrite($logfile, "$key => $value\n"); } fclose($logfile); $time_elapsed = microtime(true) - $startTime; echo "Finished after {$time_elapsed} seconds"; } /* Usage: // swapLanguages($pages->find("template=basic-page, parent=1, include=all"), "de"); // argument 1: pages array // argument 2: language name that you want to swap with the default language // A log file will be written to site/assets/logs/swaplanguage-log.txt. // It contains page IDs and fields that were swapped for each page */ /* // After executing this function for all required pages, following steps are needed: // 1. load core translation files for the language that is now your default (e.g. german translation files) to Setup->languages->default // 2. change titles of the default Language to your language (e.g. Deutsch) and the language that got swapped (e.g. English) // 3. if default language was English before swapping: delete core translation files for the language that you swapped // 4. if default language was not English before swapping: load the core translation files for that language // 4. in settings for home page, change the URL for your default language and the language that you have swapped. // Example: // Before swapping: default was en, swap language was de // After swapping: default is now de, swapped language is now en */ The function will swap page names and the contents of multi-language fields TextAreaLanguage and PageTitleLanguage. If any of you know a more generic way of checking whether a field is multi language, other than if($field->type instanceof FieldtypePageTitleLanguage || $field->type instanceof FieldtypeTextareaLanguage) that would be great. The function is also available as swap-languages.php gist. EDIT: Added field type TextLanguage to the fields that will be processed.
  3. Replacing the dynamic variable names didn't help either. I observe that this is happening only for some pages. Now I need to go and find out what these pages have in common or what makes them different from the pages that are working.
  4. Now I found a pattern. When I have the var_dump($p->$field); in place, it is working. When I comment it out, I get the error. What can that be? EDIT: I don"t even need the $p->of(false) in the foreach loop. As long as thje var_dump is in place, the error is gone.
  5. No, I set $p->of(false) just before these operations. I also tried with including $p->of(false) in the foreach. EDIT: @LostKobraKai : thank you! I changed my foreach to foreach ($p->template->fieldgroup as $field) { if($field->type instanceof FieldtypePageTitleLanguage || $field->type instanceof FieldtypeTextareaLanguage) { $fieldlog .= " {$field->name}"; var_dump($p->$field); $p->of(false); $$langDefault = $p->$field->getLanguageValue($l1); $$lang = $p->$field->getLanguageValue($l2); $p->$field->setLanguageValue($l1, $$lang); $p->$field->setLanguageValue($l2, $$langDefault); } } Strange, when I tested earlier, I had the $p->of(false) before the if statement and it wouldn't do. EDIT again: And now I suddenly get the error again, on a different page even with $p->of(false) in place. I just found that after reloading the edit screen for the page in the backend, the error disappears.
  6. In my language swap function, I iterate over all page fields and swap the languages only for multi language fields var_dump($p->id); foreach ($p->template->fieldgroup as $field) { if($field->type instanceof FieldtypePageTitleLanguage || $field->type instanceof FieldtypeTextareaLanguage) { $fieldlog .= " {$field->name}"; var_dump($p->$field); $$langDefault = $p->getLanguageValue($l1); $$lang = $p->$field->getLanguageValue($l2); //line 268 $p->$field->setLanguageValue($l1, $$lang); $p->$field->setLanguageValue($l2, $$langDefault); } } What is really boggling me is that for some pages that all have the same template basic-page, this code works fine. But for others it throws an error Fatal error: Call to a member function getLanguageValue() on string in /var/www/utgpw/site/templates/convert.php on line 268 the var_dump reveals int 27 object(LanguagesPageFieldValue)[372] public 'default' => string '404 Not Found' (length=13) public 'de' => string '' (length=0) public 'fr' => string '' (length=0) public 'es' => string '' (length=0) object(LanguagesPageFieldValue)[395] public 'default' => string '' (length=0) public 'de' => string '' (length=0) public 'fr' => string '' (length=0) public 'es' => string '' (length=0) int 1421 object(LanguagesPageFieldValue)[376] public 'default' => string 'Mantak Chia' (length=11) public 'de' => string '' (length=0) public 'fr' => string '' (length=0) public 'es' => string '' (length=0) string '<p>test</p>' (length=11) For the same field of type TextAreaLanguage in one case "$p->$field" returns an opject and in the other case a string. Now why is that? Pages where this happens have been imported through the API. I can't pull up the code that I used for the import because it is some time ago. The affected pages are working fine in the frontend, though.
  7. @tpr Then they would be presented with a backend in English. But they should have the backend in their native language. I also do page manipulations through frontend forms and there the user language determines for language fields which language to populate. So your suggestion is not an option. I am currently writing a language value swap function and will report back here.
  8. @tpr Thanks for the suggestions. As I wrote in solution #1 in my first post, from the frontend side that solution would work. But it brings problems in the backend when users with non default language are creating pages. Because page title values only fall back from default to non default languages and not vice versa. To illustrate this: user has language German assigned and creates new event. There he gets presented with the "Deutsch" Tab of the title field where he fills in his title. Now he hits save and gets an error, because there is only a german title and page name. And the default (English) title and page name do not fall back to the german value
  9. Came across this while importimg lots of pages. I agree with rajo, that languages should be activated by default when creating pages via API. ATM it is not obvious that we have to do it manually. And I just realized it after already having imported some 300 pages
  10. Thank you for your looking into this and for your input. I still need multilingual for each country because there is a core content section that is the same for all countries. And that core content needs to be available in 4 or more languages in each country. And, honestly, I am a bit scared of manipulating the DB manually. I might break the whole site. I will experiment with option 2 from my first post and post my findings here. That is, writing a script that swaps language content over. E.g. English content gets swapped with German content. Then just change language titles and URLs on homepage.
  11. I know this has been discussed in detail over the years and I read everything I could find about it in the forum. And still, no (straightforward) solution to my scenario. My situation: I set up a multilingual events directory site were instructors can sign in and manage their events. There is a core content area which is available in 4 languages. Instructors post their personal info and their events in only one language, but field labels need to be multilanguage. Therefore I need multilanguage page names and fields for them, too. The site has been running on Joomla/Seblod for 3 years already. I am currently in the process of porting it to PW. Once this is done, a skeleton of the site will be rolled out in different EU countries, so instructors in those countries have their own PW install to manage events for their country. Of course, the default language needs to be a different one in each country. And this is where my problem lies. I have the multilanguage setup with Language Support Page Names module and am working with multi-language fields in a 2.6.23 install. In the original project, the default language is English. Now I need to make a copy of the site that has German as default. Solutions that I am aware of are: 1. do a redirect for the default language homepage. For the frontend this is fine except for the /de/ appended to the home page. In the backend, the German users have language German. But German is not the default language. So when a user creates a new event, they will be presented with the German tab open for multi-language fields. When they fill in the title (PageTitleLanguage) and hit save, they get an error "Required value missing" for the title field. Because they only fill in the german title and the default (english) title is still empty, hence the error. So this is actually not a solution. 2. switch the values for multi-language fields by script (like proposed here) and rename the default's language title to "German" and adjust the URLs in the page names of the home page. While this is doable, it requires quite some effort as I will have to do this for every country. In Joomla/Seblod I can just change the default language with one click in the backend. And I am very much missing this feature in PW Finally, my question: Is there any way other than solution 2 to handle the situation? Maybe I missed some new features or maybe someone has come up with a way to truly change the default language programmatically. Thanks for reading through all of this. Any help would be very much appreciated.
  12. Just to confirm, proposed module from this thread is working fine for me in a 2.6.23 install.
  13. Thank you @Soma and @LostKobrakai That did the trick Got confused by the cheatsheet saying:
  14. Hello, I have a multilanguage page, running on PW 2.6.23. This is a conversion of a german Joomla site which already has active members. It is a requirement to have a specific format for user names which are generated from the Full Name of a user: "Test Üser" should become "Test_Ueser_1552", where 1552 is the user id. (note conversion of Umlaut Ü to Ue) I have changed and added Umlaut conversion in the InputfieldPageName settings to read: æ=ae å=a ä=ae Ä=ae ß=ss ö=oe Ö=oe ü=ue Ü=ue ... I have created a "member" template based on the user template, following instructions here. This is all working fine and I can create member users. My member template has a text field "fullname". Now I have written a small module to create my custom user name format from the fullname field: public function init() { $this->pages->addHookBefore('Pages::saveReady', $this, 'renameMember'); } protected function renameMember($event) { $page = $event->arguments[0]; if($page->template != 'member') return; $sanitizer = wire('sanitizer'); if($page->isChanged('fullname') && !empty($page->fullname)) { $name = $page->fullname; $newName = str_replace(" ", "_", $name) . "_" . $page->id; $newNameSave = $sanitizer->pageName($newName, "Sanitizer::translate"); $page->name = $newNameSave; $message = __("Benutzername wurde angepasst: ") . $newNameSave ; $this->message($message); } } But every time I try this, "Test Üser" becomes "test_ser_1552". The same goes for "Test üser". If I try "Test Güser", I get "test_g-ser_1552". So ü gets replaed by a dash -. When I create regular pages (e.g. basic-page template) the conversion of Ü and ü to ue for the page name is working just fine. Could there be a problem with using $sanitizer->pageName($newName, "Sanitizer::translate"); inside a module? Or is the username field treated differently from the page name field? Any solution would be much appreciated.
  15. if ($page->trackChange('name_of_you_field')) {...} got triggered for me on every page save, no matter if the value of my field had changed or not. Changing it to if ($page->isChanged('name_of_you_field')) {...} brought the desired result. See also $page->isChanged("field") in API cheat sheet
  16. When creating a new page with multilanguage page names, under the Settings tab there is a field for the page name for each language with an "Active" checkbox. By default the chachbox is checked How can I set them to be unchecked by default? I tried to find settings in LanguageSupport and LanguageSupportPageNames modules and in the settings for the languages.
  17. Hello, in a 2.6.22rc1 install I have a page field "workshops" that selects pages via selector "template=workshop,sort=-dat_start,dat_start>=today)". The field is in a template "anmeldungen". When I edit a page with template "anmeldungen". I can choose pages from the page field "workshops". But when I want to save that page, I get an error Page 2188 is not valid for workshop (Page 2188 does not match findPagesSelector: template=workshop,sort=-dat_start,dat_start>=today) But the workshop I am trying to save to the page field is definitely in the date range >=today. Otherwise it wouldn't be listed in the page field select dropdown. The same error is thrown when I change my selector to "template=workshop,sort=-dat_start,dat_start>=2015-11-04". Also saving pages through the API to that field doesn't work. Only if I omit the dat_start>= selector, I can save pages to the page field.
  18. Thanks for sharing. Do you now still get the warning about the page name already being in use?
  19. Having a similar scenario here and would also like to know how to avoid that message for the backend. Would you mind sharing your small module here? I think we'd need a hook before page render in that module which unsets that specific notification. EDIT: Can't seem to find much documentation for working with the notification system from the API side. Looking at Ryan's post here it seems that notifications are tied to the $user object?
  20. For file uploads, you may want to look at Soma's example gist.
  21. OK, I see. Yes, would be really nice to have such a module. I believe this post refers to how we can also delete image variations.
  22. @benbyf Do you mean to clean <img> tags from RTE fields where the associated images are gone for some reason? Take a look here. Or what does "cleaning images orphaned from the DB" mean? And making this into a module is somewhat difficult because in that module you would have to cater for all different constellations, like 3rd party modules that manipulate images, which is quite hard to anticipate for a potential module author.
  23. Sure this is another dependency. Using LESS/SASS you will always need some dependencies like preprocessors. But with package managers like bower etc. organizing dependencies is a breeze. And this can be used with any template approach, be it the delayed output strategy or not. What makes using LESS/SASS a big timesaver for me is that writing the CSS code becomes much faster. Also separating your CSS into chunks (partials) improves maintainability a lot.
  24. I was looking into cross browser save flexbox grid frameworks myself the last days and found http://leejordan.github.io/reflex/docs/. Haven't tried it yet, though. But might be worth taking a closer look.
×
×
  • Create New...