Jump to content

bernhard

Members
  • Posts

    5,616
  • Joined

  • Last visited

  • Days Won

    256

Everything posted by bernhard

  1. Thx for the additions 🙂 That would be a great use case for using $page->meta() ! It's already there without doing anything and it's also a lot easier to manipulate meta data from within a hook than updating a hidden field's content. Everything needed is doable with just a few lines of code without any modules. The modules do not help here. Quite the contrary, they make things more complicated and less robust. To add a runtime markup field to page edit: <?php $wire->addHookAfter("ProcessPageEdit::buildForm", function (HookEvent $event) { /** @var InputfieldForm $form */ $form = $event->return; $page = $event->process->getPage(); // custom rules where to add the field // eg add it only to pages with template "home" // otherwise exit early and do nothing if ($page->template !== 'home') return; $form->insertAfter([ 'type' => 'markup', 'name' => 'mymarkup', // we need that later ;) 'value' => '<h1>I am a custom markup field</h1>', ], $form->get('title')); }); In this markup field you can show any HTML/PHP markup you want. Now we can also add dynamic selects - also just a single and quite simple hook: <?php $wire->addHookAfter("ProcessPageEdit::buildForm", function (HookEvent $event) { /** @var InputfieldForm $form */ $form = $event->return; $page = $event->process->getPage(); // custom rules where to add the field // eg add it only to pages with template "home" // otherwise exit early and do nothing if ($page->template != 'home') return; // data coming from your file $races = ['foo', 'bar', 'baz']; // add all options $f = new InputfieldRadios(); $f->label = 'Choose your race'; $f->name = 'myrace'; foreach ($races as $race) { $f->addOption($race, "Use Race '$race' for something"); } // now add it after our markup field: $form->insertAfter($f, $form->get('mymarkup')); }); And finally we save the data: Another small hook 🙂 <?php $wire->addHookAfter("Pages::saveReady", function (HookEvent $event) { // get the selected race from the radio input // we sanitize the input to make sure it is a string $race = $this->wire->input->post('myrace', 'string'); if (!$race) return; // save selected race to page meta data $page = $event->arguments(0); $page->meta('myrace', $race); }); Of course we have now two hooks for the same process, so we can combine those two to one and we end up with two hooks which should all you need: <?php $wire->addHookAfter("ProcessPageEdit::buildForm", function (HookEvent $event) { /** @var InputfieldForm $form */ $form = $event->return; $page = $event->process->getPage(); // custom rules where to add the field // eg add it only to pages with template "home" // otherwise exit early and do nothing if ($page->template != 'home') return; $race = $page->meta('myrace'); $time = $page->meta('chosenat') ?: ''; if ($time) $time = date("Y-m-d H:i:s", $time); $form->insertAfter([ 'type' => 'markup', 'name' => 'mymarkup', 'value' => '<h1 class=uk-margin-remove>I am a custom markup field</h1>' . "<p>Last Chosen Race: $race (@$time)</p>", ], $form->get('title')); // data coming from your file $races = ['foo', 'bar', 'baz']; // add all options $f = new InputfieldRadios(); $f->label = 'Choose your race'; $f->name = 'myrace'; foreach ($races as $race) { $f->addOption($race, "Use Race '$race' for something"); } // now add it after our markup field: $form->insertAfter($f, $form->get('mymarkup')); }); $wire->addHookAfter("Pages::saveReady", function (HookEvent $event) { // get the selected race from the radio input // we sanitize the input to make sure it is a string $race = $this->wire->input->post('myrace', 'string'); if (!$race) return; // save selected race to page meta data $page = $event->arguments(0); $page->meta('myrace', $race); $page->meta('chosenat', time()); }); No modules, no rocket science. Just ProcessWire awesomeness 🙂
  2. Or you just use RockFrontend 😉 /* h1 fluid font size, 20px on mobile, 40px on desktop */ h1 { font-size: rfGrow(20px, 40px); } Does also work for margins, paddings, translate etc etc...
  3. This is where you make it more complicated than it needs to be 😉 You don't need to cancel the save at any stage. You just need to make sure that only the correct values are written to a dedicated field of your page. But there's nothing bad in having the file stored in one field, then process that file on save, then let the user choose the correct race and then on the next save you write the correct race to the dedicated field that only stores one race. This would be fairly easy to achieve with a custom markup field. There you process the file and display results, for example with a radio list element. The markup field could show some information like "this field will list all races from the uploaded file. please upload a file and save the page." After upload and save you present something like this: Once the user selects for example "race 2" and saves the page you take that information and save all the necessary data of race 2 to your page's dedicated fields and voila you always have the correct data in your pages and you don't need to revert anything or such. In general chances are high that this feeling is wrong 😄
  4. There are no modules for that as far as I know. What you are looking for is not so easy. ProcessWire does that by redirecting to a dedicated form that is only built for that very specific action and takes all the arguments via GET parameters: That way PW knows what to do after the confirmation was given. In that case it will remove field 102 from template 1. You see that very basic behaviour and its limitations if you try to remove fields and also try to rename the template. Then PW needs to show to confirmations and do two actions and just skips one with informing the user: That's some background to what you were asking. If you tell us more about your real use case it would be easier to think of the best solution. Details really matter here. Which fields do you want to check? Are we talking about 2? 10? 100? Can we simply wipe data if some conditions are not met and show a warning or do we need to restore old values or such?
  5. Do you really think this could be an issue? I can't tell how that behaves on huge installations but on mine I've quickly tested this and I think looping over all links should be fine: It takes 225ms for 469 pages, so if there are only a handful in a body field I don't think that it would matter?
  6. Yeah I'm indeed not using that often, but once in a while it comes in handy. What about adding a warning to db() and bdb() calls? This is the markup I used: <svg title="Warning: Dumping large objects might slow down your browser! Use d() or bd() instead." uk-tooltip style="color: orange; margin-right: 5px;" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" aria-expanded="false" tabindex="0"><g fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M0 0h24v24H0z"></path><path fill="currentColor" d="M11.99 1.968c1.023 0 1.97.521 2.512 1.359l.103.172l7.1 12.25l.062.126a3 3 0 0 1-2.568 4.117L19 20H5l-.049-.003l-.112.002a3 3 0 0 1-2.268-1.226l-.109-.16a3 3 0 0 1-.32-2.545l.072-.194l.06-.125L9.366 3.516a3 3 0 0 1 2.625-1.548zM12.01 14l-.127.007a1 1 0 0 0 0 1.986L12 16l.127-.007a1 1 0 0 0 0-1.986L12.01 14zM12 8a1 1 0 0 0-.993.883L11 9v2l.007.117a1 1 0 0 0 1.986 0L13 11V9l-.007-.117A1 1 0 0 0 12 8z"></path></g></svg> It might help others as well that are not aware of this issue.
  7. Yeah, just wanted to edit my post to state that I might need to change my habits here 🙂 I'm always using db because it's annoying to not get the full result. Didn't realise that it has that side effect. Awesome. All the settings to fix this issue are already there 🙂 Limiting the number to 20 and nesting to 3 for example makes everything stay snappy. Great! Thx for your quick help.
  8. I think I found the issue! The issue occurs if you dump a large dataset! I had some code to test the performance of a $pages->find("something") call... For that I first loaded all pages via $all = $pages->find("include=all") and dumped it via db($all) which showed the following: This was enough to make the whole page really laggy. Even when hovering the debug bar it took quite long for the pop-ups to appear. After a reload everything was snappy, so the issue occurred only after I executed the console code at least once. Seems that the dump adds so many elements to the dom that the browser can't really handle it! Not sure what we could do about this? I'm using default values for dumping:
  9. I've even had a look at the module settings!! Didn't spot it there as well - thx a lot 🙂 We'll see if that makes a noticeable difference.
  10. Hey @adrian I'm still having this issue. Can I somehow disable the autocomplete feature of the ACE editor? That would be my first guess and it's really not useful to me anyhow. I tried to find it in the code but didn't 🙂
  11. Idea: What about a shift-click feature that immediately translates the default language to the language that was clicked. We would then have the benefit of one-click translation by maintaining the benefit of instantly seeing the result.
  12. Hey @FireWire me again 🙂 What is really annoying in the translation process is when the content contains links. Unfortunately deepl can't link know about the different urls for pages in different languages. I don't have very much experience with multilingual sites yet, so I might be missing something? But for now the process for me is: Write text in german. Click on English tab. Hit translate. Fix all links that are still pointing to german urls. The annoying part here is that if I fix a typo or change one sentence I can't just hit "translate to english" because that will wipe my links as well. So I have to either translate that sentence manually or fix all links. This is not just annoying but also prone to errors. I thought maybe it would be possible to check for links in the returned result (eg via Regex or maybe even better via dom parsing) and then loop those links and automatically link them to the english version if one exists and is active. I think that should work well and I'd be happy to sponsor this addition if you help me with pointers on how the module actually works and where the translation takes place. Maybe we could even make the request that fetches data from deepl hookable so that anything would be possible and so that this feature of automatically converting links could be enabled or disabled via a checkbox in the settings.
  13. Thx @imandreas the docs are restored here: https://www.baumrock.com/en/processwire/modules/rockfrontend/docs/
  14. Ich möchte anmerken, dass ich NICHT eingeladen habe, hier auf Deutsch zu schreiben, denn das widerspricht den Forums-Regeln. Ich habe angemerkt, dass DeepL sehr gut im Übersetzen ist und eine gute Möglichkeit sein kann, wenn man Probleme mit Englisch hat. Die Idee war aber, den Post auf Deutsch zu verfassen, dann mit DeepL zu übersetzen und dann auf Englisch hier zu posten. I would like to note that I did NOT invite people to write in German here, because that is against the forum rules. I noted that DeepL is very good at translating and can be a good option if you have problems with English. But the idea was to write the post in German, then translate it with DeepL and then post it here in English. CAUTION: This script is likely NOT doing what you want. The selector selects the "authlogs" page, which is the parent page! You want to delete "authlog" pages. CAUTION2: If you change the selector from "authlogs" to "authlog" then it will delete ALL authlog pages, not only old ones. You'll probably want something like this: <?php $cutoff = strtotime("2023-09-01"); $pages->find("template=authlog, your_date_field < $cutoff"); PS: Considering that the selector was wrong that would also explain why it didn't change the page count: You tried to delete the parent page, which is not possible unless you delete all children first. So the script actually did nothing and the count didn't change.
  15. Hey Frank, you are very vague with your information that you give us. Therefore it's not easy to help. If english is a problem for you just write your question in german on deepl.com/translator and copy paste the english version here. Which table? A database table? Or PW pages? Where is your date stored? In a regular PW field? Then it would be a simple $pages->find("your_date_field<..."); But we don't know anything about your setup, so nobody can really help.
  16. You can use TextformatterRockDown for that. You can any custom tags you like.
  17. Ok so ALFRED will stay in RockFrontend, thx for letting me know @gornycreative and @MarkE That's not intentional behaviour and I've never experienced something like this. If you provide instructions on a fresh installation with step by step guide to reproduce the issue I can have a look into it.
  18. I'm aware of container queries being something coming in the future but I thought it's not there yet or at least not well enough supported to be used just now. Let me know if I'm wrong and I'm happy to add support for it if that's possible. I think rfGrow() is a great helper and I'm happy that it's useful for you as well 🙂
  19. Ok then maybe Jumplinks hooks after pageview and so that track404 is called nonetheless. You could also hook after pageview and make sure that your hook has a very low priority to make sure it fires at the very end (after all other modules that might have hooks attached).
  20. Great. Yeah that's the lowest hanging fruit I guess. Your concerns about my other suggestions make a lot of sense. And I'd not call the way it is "really annoying". It would just be the icing on the cake. But not if it makes things worse, of course, so please take your time to make a good decision - I was just throwing in ideas 🙂 To the flip: Where that translation screen can be handy is the following. I'm working on my website which will be german as default and english as second language. Some texts have been in english originally because I was working with a non german designer on the website. Now I need to translate those sections into german, which is not possible with Fluency, because it doesn't allow translating from the second to the first language. I could also use the deepl website for it, but I'm using informal language (eg "Was willst du kaufen?" rather than "Was wollen Sie kaufen?") and the online translator of deepl does not allow me to select that informal version 🙂 I'd have to pay, so it's better to either translate it myself or rewrite the translation after copying. In Fluency I can select the less formal version and I get the correct translation instantly 🙂
  21. Another one that would boost my workflow: Guess what I want to do... Translate it to english 🙂 But that needs two clicks, one on "english" and one on "translate". Why not show all available languages right beside "Translation Available"? I guess that's the case 99% of the time - you enter text in the default language and want to translate it to other languages. What about something like this? Translation Rready | Translate to: EN, ES, GR or to all languages I know it's a very small thing, but for me when working with RockPageBuilder I have Text usually split into many blocks, so that means a lot of clicks for translating blocks and if I could half that amount that would be very welcome 🙂 PS: A problem with that approach would be that you don't see the result of the translation whereas with how it is now you instantly see the result because you are on the right tab. Maybe it could jump to the tab after translation? Not sure how that would work for the "all languages" though, but I guess it would still be nicer to click "translate to all" and then click through all the tabs to check the result rather than clicking every language and translating it one by one...
  22. Hey @FireWire another little suggestion: The config shows two languages for this site, but when opening the translator it shows this: This site has only two languages and when using the translator it's most likely because I want to translate something from German to English or vice versa. It would be great if "translate to" had "English (British)" preselected. And it would be great to add a little button between those fields to flip them. Similar to route calculation services where you can flip route from a --> b with a single click to b --> a Thx again for this really awesome module.
  23. Recent versions of RockMigrations also show you all the settings and their possible values once the module is installed just by hovering over the setting. I'd recommend using this technique rather than copying all the code. Most of the time that is easier and you don't end up with messy migration code...
  24. It seems to be a common misconception that if you start using RockMigration there is no way back and you need to use RockMigrations for everything. That's not the case.
  25. RockMigrations has a lot more to offer. It has a proven workflow for professional and automated deployments for example and it comes with MagicPages that have a lot of great helpers if you are using custom page classes. It has helpers to make working with the page editor easier (eg the wrapFields() method) and it has helpers to quickly see all the properties you need via mouse hover. Even if I died tomorrow you could just continue using RockMigrations for the next 10 years. If anything is not supported, just go with the regular API. If anything breaks with future updates, just remove RockMigrations from the project and that's it. From that time on you could rely on core api and just remove old code (if that's even necessary). But there's nothing bad in using the core api if you prefer. It's just too cumbersome for me.
×
×
  • Create New...