Skip to content

Commit

Permalink
feat: add murl pagefile property tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Feb 4, 2024
1 parent 880ff03 commit 6cf026b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tweaks/ImageMurl.php
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";
}
}

0 comments on commit 6cf026b

Please sign in to comment.