Jump to content

da²

Members
  • Posts

    396
  • Joined

  • Last visited

  • Days Won

    5

Everything posted by da²

  1. Salut @Webjack, On va le faire en anglais si ça te dérange pas, ce sera compréhensible par tout le monde. ? Yes this is a PHP version issue, it's about union type "string | int" introduced in PHP 8. You have issues in your system installation, none of MySQL or other PHP extensions are found. These requirements are validated at the begin of PW installation. ProcessWire works fine with PHP 8+.
  2. You can hook "saved" method. When you don't want to trigger hooks on a page save you can use: $page->save(options: ['noHooks' => true]);
  3. @uzlander I'd use saveReady and isNew() to initialize a default value, so the hook only apply the first time page is created: $this->addHookBefore('Pages::saveReady(template=my-template)', function (HookEvent $event): void { $page = $event->arguments(0); if ($page->isNew()) { $page->myField = "myDefaultValue"; } }); Or like this, replacing isNew() by id=0 in hook selector: $this->addHookBefore('Pages::saveReady(template=my-template, id=0)', function (HookEvent $event): void { $page = $event->arguments(0); $page->myField = "myDefaultValue"; });
  4. It's hard-coded for now but I will eventually move it to a PW config page, so my clients can change it. Having it in a template wouldn't help because I highly discourage my clients to go in templates/fields area, it's way too much dangerous for a non-developer (their standard accounts can't access here).
  5. The first time I had a look to Drupal I didn't find how to create a basic page, like just... "can I create a template?", "where do I write php code?", "where do I add a <div>"? Sometimes I go in Drupal documentation, just having a quick look, there's a lot, a lot, a lot of documentation, there is so much to read, but for so little useful information. It's like a big wall where you would look for a door to pass through that you never find. I don't lose hope; perhaps one day I'll have enough motivation to find that door. ?
  6. So it seems this is field assignation that triggers change detection, it works like that: $pageSessions = $page->raceSessions; $pageSessions->removeAll(); foreach ($sessionsTemplate->raceSessions as $raceSession) $page->raceSessions->add($raceSession); $page->raceSessions = $pageSessions; // Assignation triggers change detection
  7. @MarkE This is a saveReady hook, page will be saved at the end.
  8. I think what is triggering changes detection may be field assignation: $page->myField = $newValue. But then I'm stopped by this bug.
  9. Hello, I was working on a hook that updates a matrix repeater. I have another hook that should trigger when this repeater is changed, and I found it is not triggered. So I thought that changes are not triggered by API changes (only user changes in admin), so that I should call the second hook myself. But I did another test with "title" field, and found it is triggered by API change. ?‍♂️ I plan to report the issue on GitHub, but want to ask here before in case I'm missing something. The following code updates the matrix repeater from another repeater, then I update title, then I check if repeater and title changes are tracked, and only title one is: protected static function onSaveReady(HookEvent $event, EveningRacePage $page, mixed $eventObject): void { /** @var RaceSessionsTemplatePage $sessionsTemplate */ $sessionsTemplate = $page->raceSessionsTemplate; $page->raceSessions->removeAll(); foreach ($sessionsTemplate->raceSessions as $raceSession) $page->raceSessions->add($raceSession); $page->title = $page->title . "1"; $changes = $page->getChanges(true); wire()->log->message("title changed" . array_key_exists('title', $changes)); // 1 wire()->log->message("raceSessions changed" . array_key_exists('raceSessions', $changes)); // 0 }
  10. Hey, I see your idea like having static properties, instances are pages and static properties are on template. I don't know it this is a good idea, on my side, since I discovered custom page classes I declare this on UserPage for example: public function getAvatar(): string { return $this->avatar ?: wire()->config->urls->templates . 'img/default-avatar.png'; } I could also have the default avatar on a generic configuration page.
  11. In my test I did an exit(), if I remove it it throws an error. ? $this->addHookAfter('InputfieldRepeater::renderRepeaterLabel', function(HookEvent $event) { $page = $event->arguments(2); $page->getForPage(); // Comment this line and there's no more error // exit(); // Or uncomment this }); Error comes after our call to getForPage(): It seems that calling getForPage() triggers an error later in PW code... Looks like a bug to report. In getForPage() source code we can see: // this probably can't occur, but here just in case $this->forPage = $this->wire('pages')->newNullPage(); Looks like it occurs @ryan ?
  12. Oh ok I see, so getForPage() works on my side (PW 3.0.228): /** @var RepeaterMatrixPage $page */ $page = $event->arguments(2); $templateName = $page->getForPage()->template->name;
  13. Hello, There isn't a getForPage() method on Page class. To access parent template it's simple: $page->parent->template->name.
  14. Damned, I have always thought that custom page classes were usable only in template.php files. ?‍♂️ This evening I wanted to hack PW to create a template/CustomPageClass mapping usable everywhere with PW API (get, find, etc), and in the first 3 minutes I found it was already there. ? This is huge, I love it and am already refactoring some code and twig templates with a custom UserPage, using Traits to share some implementation with my RawUser class (an optimized class from direct database query). I'm quite excited! ?
  15. There are 2 types of bookmarks, one defined in template and that can be disabled, and one that you create manually on bookmarks pages, selecting a parent page. The first one uses label defined in templates (or template name if not defined), that's the one I was talking about. I thought that was your question. The second one use parent page name, and I don't how you can change this, maybe with a hook?
  16. @Nick Belane In template configuration -> first tab > label. ?
  17. @dotnetic Maybe I misunderstood, I thought he doesn't want the image to be loaded below a certain screen size. And since URL comes from a ProcessWire page he can't push it in a CSS and use media queries. In this case I tested the following and it's working: <style> :root { --myImageUrl: url('{{ pages.get(5872).gameLogoLarge.url }}'); } body { /* This part can be in external CSS. */ @media screen and (min-width: 640px) { height: 100vh; background: var(--myImageUrl) no-repeat fixed center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } } </style> Note that it works on <body> but not <html>, but I don't think you have to put something on html except (maybe) the "height:100vh".
  18. Hello, my first idea would be to pass image URL to a CSS variable, so you can use media query to condition loading of image. There may be a more elegant solution, maybe using <picture>? (I never used it yet)
  19. Strange, on my side it works in every language.
  20. You should try put it in site/config.php. I see that LanguageSupportPageNames uses $config->pageNumUrlPrefix so I'm not sure if it needs more configuration. It looks like in source code that if you don't define it for every language it will use the one from config.
  21. Hello @joe_g Yes I don't think this is a good place to define functions. When calling wire404(), a new template is rendered (page-404), so _init file is called again. But you may do it with a constant: if (!defined('FUNCTIONS_INITIALIZED')) { function test():void { echo "Hello"; } define('FUNCTIONS_INITIALIZED', true); } For global functions I prefer to create static classes in different packages, each class for a single context. When using custom Page classes, it's also possible to add this functions as methods in a base MyCustomPage class, and call them with $page->myMethod().
  22. Hi @brodiefarrelloates Could it come from an outdated module? What says the stack trace? (should be in errors log) In my PW database I don't have any "sessions" table, only a session_login_throttle. EDIT: OK I see it comes from wire\modules\Session\SessionHandlerDB\SessionHandlerDB.module. I have no idea when this module is triggered but you can see in source code the SQL query to create "sessions" table: public function ___install() { $table = self::dbTableName; $charset = $this->wire()->config->dbCharset; $sql = "CREATE TABLE `$table` (" . "id CHAR(32) NOT NULL, " . "user_id INT UNSIGNED NOT NULL, " . "pages_id INT UNSIGNED NOT NULL, " . "data MEDIUMTEXT NOT NULL, " . "ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, " . "ip INT UNSIGNED NOT NULL DEFAULT 0, " . "ua VARCHAR(250) NOT NULL DEFAULT '', " . "PRIMARY KEY (id), " . "INDEX (pages_id), " . "INDEX (user_id), " . "INDEX (ts) " . ") ENGINE=InnoDB DEFAULT CHARSET=$charset"; $this->database->query($sql); }
  23. @MarkE My approach is a bit different and very basic. I don't plan to migrate pages or anything else than fields and templates configuration, nor to interpret data or use PW API or track user changes with hook, it's just a raw database process. That's why there are more drawbacks and limitations. If one day I need a real migration tool I'll use RockMigrations or ProcessDbMigrate. ?
  24. I'm also interested in this use case, I'm also curious of the feasibility and I need a short "brain pause" from my current project, so I'm trying some experiments for fun. Like @bernhard said this approach have limitations and drawbacks, at least: You must be sure that both databases use same ID for fields and templates (and maybe more like languages...), But if that's not the case, we may fallback on field and template name, except when field/template has been renamed. Nobody can manually change fields and templates on the target installation, Some data can not be updated so easily, like the field type that can require changes on database structure, Maybe some data in "data" column ("fields" and "templates" database tables) can not be changed so easily too (I see for example some "parent_id" properties), Probably more drawbacks... ? But anyway, I find the idea interesting and am having fun experimenting this. Actually I have some bit of code that do 2 things, compare "fields" table from 2 PW installation and display a summary of the changes. Example of output: Next step should be to update database, and adding sanity checks to avoid some kind of changes (like on field type). But I'm not confident at all to use this on a production server before a lot of tests and a confirmation by Ryan and other PW developers that there's not risk updating what I'm gonna update. ? I'm not even sure I'll use it one day, this is actually just experimentation for fun and curiosity.
  25. But find() searches in current language AND default one. I assume OP wants to search only in one language. https://processwire.com/docs/multi-language-support/multi-language-fields/#how-language-fields-work
×
×
  • Create New...