Skip to content

Commit

Permalink
feat: add warning that ALFRED needs frontend module
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Apr 9, 2024
1 parent b06e09d commit 971ef4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions RockFrontend.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class RockFrontend extends WireData implements Module, ConfigurableModule
const field_images = self::prefix . "images";
const field_less = self::prefix . "less";

private $addMarkup;

/** @var WireData */
public $alfredCache;

Expand Down Expand Up @@ -234,6 +236,7 @@ public function init()
wire()->addHookMethod("Page::otherLangUrl", $this, "otherLangUrl");
wire()->addHookAfter("Modules::refresh", $this, "livereloadResetCache");
wire()->addHookAfter("Page::render", $this, "livereloadAddMarkup");
wire()->addHookAfter("Page::render", $this, "hookAddMarkup");

// others
$this->ajaxAddEndpoints();
Expand Down Expand Up @@ -559,6 +562,11 @@ public function alfred($page = null, $options = [])
{
if (!$this->alfredAllowed()) return;

// check if frontend editing is installed
if (!$this->wire->modules->isInstalled("PageFrontEdit")) {
$this->addMarkup .= "<script>alert('Please install PageFrontEdit to use ALFRED')</script>";
}

// support short syntax
if ($options === false) {
$options = [
Expand Down Expand Up @@ -1271,6 +1279,21 @@ public function hideLayoutField(HookEvent $event)
$form->remove(self::field_layout);
}

/**
* Inject markup to the page body
* @param HookEvent $event
* @return void
*/
protected function hookAddMarkup(HookEvent $event)
{
if (!$this->addMarkup) return;
$event->return = str_replace(
"</body>",
$this->addMarkup . "</body>",
$event->return
);
}

/**
* Return a latte HTML object that doesn't need to be |noescaped
* @return Html
Expand Down
2 changes: 2 additions & 0 deletions docs/alfred/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ It has two main goals:

See the video here: https://www.youtube.com/watch?v=7CoIj--u4ps&t=1714s

<div class='uk-alert uk-alert-warning'>Note: To use ALFRED you need to install the PageFrontEdit module and make sure all users have the page-edit-front permission.</div>

## Easier Frontend Editing for Your Clients

A typical example that almost every website has are footer links - that's why RockFrontend comes with a migration that creates a footerlinks field for you. It creates that field on the `home` page and the client can manage the footerlinks by editing the `home` page in the PW backend.
Expand Down

0 comments on commit 971ef4a

Please sign in to comment.