Skip to content

Commit

Permalink
feat: add PageListShowTemplate tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Mar 22, 2023
1 parent c548a78 commit 40c49e8
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tweaks/PageListShowTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace RockMigrations\Tweaks;

use ProcessWire\HookEvent;

class PageListShowTemplate extends Tweak
{
public $description = "Shows the page template in page tree for SuperUsers";

public function ready()
{
if (!$this->wire->user->isSuperuser()) return;
if ($this->wire->page->template != 'admin') return;
$this->wire->addHookAfter('ProcessPageListRender::getPageLabel', $this, "hookPageLabel");
$this->wire->addHookAfter("Page(template=admin)::render", $this, "addStyle");
}

public function addStyle(HookEvent $event)
{
$event->return = str_replace(
"</head>",
"<style>
.PageListTemplate{
color:#afafaf;
margin-left:5px;
font-size:0.7rem;
}
</style></head>",
$event->return
);
}

public function hookPageLabel(HookEvent $event)
{
$page = $event->arguments('page');
$event->return .= "<span class='PageListTemplate'>[{$page->template}]</span>";
}
}

0 comments on commit 40c49e8

Please sign in to comment.