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:
| File | Who can open it | Address |
|---|---|---|
routes/guest.php | Everyone | /x/vendor-name/... |
routes/member.php | Signed-in, approved members | /x/vendor-name/... |
routes/admin.php | Admins | /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());
}
| Slot | Where |
|---|---|
header | Under the forum header, on every page |
footer | Above the forum footer, on every page |
sidebar | In the sidebar, on pages that have one |
above_board | Above the forum list on the home page |
below_board | Below the forum list on the home page |
between_posts | Between two posts in a topic. Gets position |
reply_author | Under the author in each post. Gets member |
reply_author_stats | In the author details of each post. Gets member |
profile_header | In the header of a member profile. Gets member |
page_end | At the very end of every page |
forum_header | Above the topic list of a forum. Gets forum |
topic_header | Above the first post of a topic. Gets topic |
topic_end | Below the last post of a topic. Gets topic |
post_footer | Under the text of each post. Gets reply and member |
reply_composer | Below the quick reply box of a topic. Gets topic |
content_top | At the top of the content on every forum page. Gets route, the page name |
content_bottom | At the bottom of the content on every forum page. Gets route |
page_head_actions | Next 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.