Skip to content

Commit

Permalink
feat: add $pagefile->isImage property hook
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Jan 29, 2024
1 parent 89ee09b commit 43a06de
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions RockMigrations.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public function init()
$this->addHookAfter("Modules::refresh", $this, "hookModulesRefresh");
$this->addHookAfter("Pages::saved", $this, "resetCachesOnSave");

// core enhancements
$this->wire->addHookProperty("Pagefile::isImage", $this, "hookIsImage");

// other actions on init()
$this->loadFilesOnDemand();
}
Expand Down Expand Up @@ -2006,6 +2009,28 @@ public function homeTemplate(): Template
return $this->wire->pages->get(1)->template;
}

/**
* Add $file->isImage property to pagefile objects until this feature is in the core
* See https://github.com/processwire/processwire-requests/issues/517
* @param HookEvent $event
* @return void
*/
public function hookIsImage(HookEvent $event): void
{
$file = $event->object;
$event->return = false;
switch ($file->ext) {
case "jpg":
case "jpeg":
case "gif":
case "png":
case "tiff":
case "webp":
case "svg":
$event->return = true;
}
}

/**
* DEPRECATED
*
Expand Down

0 comments on commit 43a06de

Please sign in to comment.