Start free trial

Extensions (PHP) · Page takeovers

Page takeovers

An extension can answer one of the board's own forum pages with its page instead: your own search on /search, a different member list on /members, a new layout for a forum. Members keep using the same address and the same links, and the board sends the request to your class.

Make one

php artisan fs:make takeover search.index

This adds src/Takeovers/SearchIndexPage.php and a view in views/takeovers. Run fs:sync and open the page. Developer, Replaceable pages in the admin panel lists every page name you can use and which pages are taken over on your board.

The PageTakeover contract

class SearchIndexPage implements PageTakeover
{
    public function route(): string
    {
        return 'search.index';
    }

    public function handle(Request $request): mixed
    {
        $forumIds = app(BoardSearchService::class)->viewableForumIds($request->user());

        return view('acme-search::results', [
            'query' => (string) $request->query('q'),
            'topics' => Topic::whereIn('forum_id', $forumIds)->where('title', 'like', '%'.$request->query('q').'%')->latest()->limit(20)->get(),
        ]);
    }
}

handle() gets the request with its route parameters already resolved, so $request->route('topic') is the topic model on a topic page. Return a view, a response, a redirect or anything else a controller may return.

You check permissions

The board runs its middleware first (the board being offline, bans, the member's group), but the checks inside the core controller do not run, because your class replaces it. Check what the page needs yourself, with the same checks the board uses: Gate::allows('read', $forum) and Gate::allows('read', $topic) for one item, BoardSearchService::viewableForumIds() for lists across forums. Forgetting this shows private content.

How the board chooses

  • Only forum pages answered with GET can be taken over. Admin, Mod CP, sign-in and account security, install, billing and checkout pages never can, so no extension can ask for a password or a payment in the board's name.
  • If two extensions take over the same page, the one installed first is used.
  • If your class throws, the error counts against your extension and the board shows its own page. Too many errors and ForumSpark switches the extension off.
  • Admins see on your extension's row in Apps, Extensions which pages it replaces, and can give a page back to the board from its menu without turning your extension off.
  • Page actions (beforeAction() and afterAction()) still run around a taken-over page.
  • fs:check warns about a class in src/Takeovers that does not implement PageTakeover.

Replace a service instead

When you only want a different engine behind a page (AI text, image moderation, the registration check), a replaceable service keeps the board's page, its permissions and its look, and is less work to keep up to date.