Start free trial

Extensions (PHP) · Pages, tables and settings

Pages, tables and settings

Pages

Pages are ordinary Laravel routes in three files. ForumSpark adds the address prefix and the right middleware for you:

FileWho can open itAddress
routes/guest.phpEveryone/x/vendor-name/...
routes/member.phpSigned-in, approved members/x/vendor-name/...
routes/admin.phpAdmins/admin/x/vendor-name/...
Route::get('/map', fn () => view('harbour-member-map::map'))->name('map');

Link to a page with ext_route('harbour/member-map', 'map'), or ext_route('harbour/member-map', 'settings', area: 'admin') for an admin page. Views use the vendor-name:: prefix.

Adding to existing pages

To show something on the forum's own pages, like a badge under every post, write a class that implements App\Modules\Contracts\PageSlot and list it in your extension's contributes(). Return the slots you fill and render them; ForumSpark passes what the slot knows about, like the topic or the member.

public function slots(): array
{
    return ['post_footer'];
}

public function render(string $slot, array $context = []): ?Htmlable
{
    return new HtmlString(view('harbour-member-map::pin-badge', ['member' => $context['member']])->render());
}
SlotWhere
headerUnder the forum header, on every page
footerAbove the forum footer, on every page
sidebarIn the sidebar, on pages that have one
above_boardAbove the forum list on the home page
below_boardBelow the forum list on the home page
between_postsBetween two posts in a topic. Gets position
reply_authorUnder the author in each post. Gets member
reply_author_statsIn the author details of each post. Gets member
profile_headerIn the header of a member profile. Gets member
page_endAt the very end of every page
forum_headerAbove the topic list of a forum. Gets forum
topic_headerAbove the first post of a topic. Gets topic
topic_endBelow the last post of a topic. Gets topic
post_footerUnder the text of each post. Gets reply and member
reply_composerBelow the quick reply box of a topic. Gets topic
content_topAt the top of the content on every forum page. Gets route, the page name
content_bottomAt the bottom of the content on every forum page. Gets route
page_head_actionsNext to the buttons in the head of every page that has one. Gets route

content_top, content_bottom and page_head_actions are on every forum page. Check $context['route'] to pick the pages you want, like topics.show or members.index, and return null everywhere else.

If your slot fails, ForumSpark logs it and leaves the slot empty; the rest of the page still shows.

Tables

Migrations live in a folder per version, like migrations/1.0.0/001_create_pins.php. Table names start with ext_ and your extension's id, like ext_harbour_member_map_pins, so they never clash with ForumSpark or another extension. Each new version keeps the old migrations and adds new ones, so a forum that skips a version still updates cleanly.

The Developer section has a table editor: add tables and columns with a form and it writes the migration.

Settings

Settings are options admins change for their forum. Declare them in your class; ForumSpark builds the settings page, which admins open from the extension's menu on the Extensions page.

public function settings(): SettingsSchema
{
    return SettingsSchema::make([
        'pins_per_member' => ['label' => 'Pins per member', 'type' => 'int', 'default' => 5, 'rules' => ['integer']],
    ]);
}

The Settings form in the Developer section adds them for you. Read a value with $this->setting('pins_per_member').

Give every setting a label. The board uses it to list the setting in the admin search, so admins find it by name, and on Developer, All settings, next to every board setting and its rules.

Translations

Every sentence goes in lang/en/messages.php and is shown with __('harbour-member-map::messages.title'). Forums translate them in their own languages. The check warns about sentences your code uses that have no text, and texts nothing uses any more.