Jump to content

da²

Members
  • Posts

    341
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by da²

  1. I was struggling, trying permissions, searching in PW source code and the web, thought about a bug... and while taking 1 minute of pause I saw this thread in forum activity tab and thought "OK let's give a try with ChatGPT, I have no idea anyway right now". Question: (I already used template access control, but for some reason I thought user access control was managed by permissions (user-view, user-admin...)). Answer (in bold what I was looking for):
  2. Hello, Error message says there's no property "field" on Page class. There are also some more mistakes. This should be better: public function ready() { $this->pages->addHookBefore('saveReady', function($event) { // Replaced saved with saveReady $page = $event->arguments(0); // Replaced [0] with (0) $summaryField = $page->summary; // Removed ->field('name') $bodyField = $page->body; // Removed ->field('name') if (empty($summaryField)) { // Removed ->value $page->summary = strip_tags(substr($bodyField, 0, 192)); // replaced $summaryField->value with $page->summary, $bodyField->value with $bodyField } }); } Note that "save" hook is executed after the page is saved, so it's too late. Documentation : Page and Pages hooks EDIT : Note that you can also do that without creating a module, just by adding the hook ($this->pages->addHookBefore...) in site/templates/admin.php
  3. @joe_g What do you mean by adding roles dynamically? $page->authors->add($john);
  4. Hi @antoine.ctrs, did you read MAMP Pro documentation first? Setting a server environment is not specifically related with ProcessWire. You can test your installation with a simple index.php and a phpinfo() call. When it works, try with ProcessWire (unzip folder in a served directory and go to this URL with your browser).
  5. That's probably the issue. print_r output shows it's a PageArray, so we can't call PageArray->title. Instead of editing the code it's better to edit the PageReference configuration to set it to a single page and choose a single selection mode (a competition has only one winner):
  6. You should try this. ? And this: echo("<pre>" . print_r($championship->winner_name, true) . "</pre>"); exit(); And maybe show the configuration of the PageReference field. I have no idea what is going on. ?
  7. Reading that I understand you are not using the User template, isn't it? So the property is still "title" and not "name". Could you post 2 screenshots from PW admin? One of the "player" template properties (the green bars), and one of the "player" page with ID 1442.
  8. No, how to store thousands of users on 2 digits ? ?
  9. Ohhhhhhhhhhhhhhhhhhhhhhhhhhhhh yeah I understand, we are all forgetting something tiny but quite important: the property to use on User is "name" instead of "title". ? $playerChampionships = $pages->find("template=Championship_results, winner_home_club={$page->id}"); foreach($playerChampionships as $championship) { echo "<li><a href='$championship->url'> $championship->title - {$championship->winner_name->name}</a></li>"; } Property "winner_name" should be renamed to "winner" since it's a User instance and not a string. ?
  10. Hello, I can't reproduce here on PW 3.0.228, what version are you using and are you sure you don't test this page with a superuser (who has access to everything)?
  11. @JerryDi Looks like you missed something when adding "->title". I suppose you wrote: echo "<li><a href='$championship->url'> $championship->title - {$championship->winner_name}->title</a></li>"; instead of: echo "<li><a href='$championship->url'> $championship->title - {$championship->winner_name->title}</a></li>";
  12. I'd like to add a Fieldset Tab on this page where I put fields related to race results. Is it possible to focus this tab (display its content) via API in a hook? EDIT : forget this question, after saving a page it stays on the same tab it was before, so I don't need this finally.
  13. Hello @sz-ligatur Months are now translatable in wire/core/WireDataTime : https://github.com/processwire/processwire-issues/issues/1774#issuecomment-1618267798
  14. Yes your code works, but my question is: why my code is working when field is empty but not when filled, is that a bug? (so I will report the issue)
  15. Hi, A script is updating a PageReference field that can contain multiple pages. It works when field is empty, but I just found the already filled field is not saving changes. $classPageIds = [16988]; echo($page->carClasses); // [16569, 16988] $page->carClasses = $classPageIds; echo($page->carClasses); // [16569, 16988] NO CHANGES So I have to remove all items before: $page->carClasses->removeAll(); $page->carClasses = $classPageIds; That looks like a bug but I'm asking before to report an issue, in case I'm doing this the wrong way.
  16. @joe_g Why not adding on "article" template 3 fields (PageReference for multiple pages of template "user"), "authors", "photographers", "editors"? wire()->pages->find("template=article, authors|photographers|editors=$joan->id"); wire()->pages->find("template=article, authors=$joan->id");
  17. Thanks for the answers, the idea of having two consecutive saves is acceptable. ? I didn't think about it. I didn't know about page meta data too. Just one question, is there a reason you are using "input" instead of "$page->myrace"? $race = $this->wire->input->post('myrace', 'string');
  18. OK I see, thank you for the explanation. I'm building a site and set of tools to manage sim-racing events in a league (races, championships...). The concerned page is a sim-racing race page where the user can upload a file containing race results and statistics. Problem is that this file may sometimes contain several races, and only one must be processed, but I don't know which one and the user at this point may also not know, so my idea is: 1) User upload the file and click save, 2) I parse the file, and if I find several races I cancel the save and display to the user a summary of the races contained in the file (to help him make the good choice) with a field where he can enter the race number he wants to process, 3) User enter the race number and click save again, 4) I process the file (the chosen race) and fill the page with results. One constraint is that I don't want to parse the file every time the page is saved, but only when the file has changed. I say that because I was thinking of using a hook on ProcessPageEdit::processInput(raceResultFile!="") but I failed to detect if the field has changed in this hook. Actually I feel this is impossible to achieve with simple hooks, but I may miss something.
  19. Hello, When deleting a field from a template, PW prompts the user to confirm that this field must be deleted. I'd like to use this behavior in my own code: 1) User save the page, 2) In a save hook I process data in the page, 3) If necessary (depending of data in the page) I prompt the user for a choice between multiple, so I want to display checkboxes. At this point page is not saved. 4) User select a checkbox and click save again, 4) I read the selected checkbox and continue to process page data before page is saved. How to achieve this? What PW module or functions allow to prompt user when he's saving a page and displaying a form to make some choices?
  20. Ho yes, tthat's the good way to get module instance. ? But the original issue about editor isn't solved, for example if you want completion on this module by adding a php comment it won't work. /* @var TextformatterMarkdownExtra $md_formatter */ Maybe VSCode PHP extension is not parsing .module files by default, and maybe that's configurable? I used VSCode for a few years but use PHPStorm now and will never go back. ^^ In PW admin, in your field configuration > Details > Formatter, select the formatter for markdown. Then you just use $page->field to get the formatted value.
  21. Hello, You probably have to configure you VSCode project base directory on processwire directory (parent of "site" and "wire" directories where the modules are located).
  22. @adrianOK I didn't know. Since the Upgrades module is backing up DB I thought it was updating itself.
  23. The Upgrades module backup and upgrades the database, so I don't think you can achieve an update without using it, or at least it looks dangerous as you don't really know if something is missing in DB.
×
×
  • Create New...