Jump to content

da²

Members
  • Posts

    349
  • Joined

  • Last visited

  • Days Won

    4

Everything posted by da²

  1. This returns only first level children. If you want grandchildren at any level I think you need to create a recursion function.
  2. Yes at least you'll get rid of errors if they prevent PW to work. There's also a database table "modules" that references installed modules I suppose, I don't know if it's preferable to remove module entry or not.
  3. 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+.
  4. 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]);
  5. @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"; });
  6. 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).
  7. 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. ?
  8. 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
  9. I think what is triggering changes detection may be field assignation: $page->myField = $newValue. But then I'm stopped by this bug.
  10. 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 }
  11. 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.
  12. 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 ?
  13. 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;
  14. Hello, There isn't a getForPage() method on Page class. To access parent template it's simple: $page->parent->template->name.
  15. 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! ?
  16. 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?
  17. @Nick Belane In template configuration -> first tab > label. ?
  18. @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".
  19. 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)
  20. Strange, on my side it works in every language.
  21. 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.
  22. 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().
  23. 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); }
×
×
  • Create New...