-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add murl pagefile property tweak
- Loading branch information
1 parent
880ff03
commit 6cf026b
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace RockMigrations\Tweaks; | ||
|
||
use ProcessWire\HookEvent; | ||
|
||
use function ProcessWire\wire; | ||
|
||
class ImageMurl extends Tweak | ||
{ | ||
public $description = "Adds \$pagefile->murl property"; | ||
|
||
public function ready() | ||
{ | ||
wire()->addHookProperty("Pagefile::murl", $this, "murl"); | ||
} | ||
|
||
public function murl(HookEvent $event): void | ||
{ | ||
$file = $event->object; | ||
$url = ltrim($file->url, "/"); | ||
$path = $this->wire->config->paths->root . $url; | ||
$m = $this->rockmigrations()->filemtime($path); | ||
$event->return = "/$url?m=$m"; | ||
} | ||
} |