Skip to content

Commit 6320bc0

Browse files
authored
docs: document reset settings button for extension admin pages (#521)
1 parent ee07172 commit 6320bc0

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

docs/extend/admin.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,45 @@ This page will be shown instead of the default.
265265

266266
You can extend the [`ExtensionPage`](https://api.docs.flarum.org/js/2.x/classes/flarum.admin_components_extensionpage.extensionpage) or extend the base `Page` and design your own!
267267

268+
### Reset Settings Button
269+
270+
`AdminPage` provides a `resetButton()` method that renders a **Reset Settings** button. When clicked, it opens a confirmation modal listing the setting keys that will be deleted from the database, reverting them to their PHP-side defaults (as registered via `Extend\Settings()->default(...)`).
271+
272+
On default extension pages (those that use `Admin.setting()`), the reset button is rendered automatically alongside the save button. On custom pages, you must call `resetButton()` yourself.
273+
274+
The simplest approach is to pass a label as the third argument to `this.setting()` when reading each setting. The reset button will then pick up those labels automatically when called with no arguments:
275+
276+
```js
277+
content() {
278+
const myValue = this.setting('acme.my_key', '', app.translator.trans('acme.admin.my_key_label'));
279+
280+
return (
281+
<Form>
282+
{/* ... your form fields ... */}
283+
<div className="Form-group Form-controls">
284+
{this.submitButton()}
285+
{this.resetButton()}
286+
</div>
287+
</Form>
288+
);
289+
}
290+
```
291+
292+
If you need more control, you can pass the settings list explicitly:
293+
294+
```js
295+
this.resetButton(
296+
[
297+
{ key: 'acme.setting_one', label: app.translator.trans('acme.admin.setting_one_label') },
298+
{ key: 'acme.setting_two', label: app.translator.trans('acme.admin.setting_two_label') },
299+
],
300+
app.translator.trans('acme.admin.reset_title', {}, true), // optional modal title
301+
'acme-extension' // optional extension ID, included in the Reset event payload
302+
)
303+
```
304+
305+
When a reset is confirmed, a `Flarum\Settings\Event\Reset` event is dispatched on the backend with the `$actor`, `$extensionId`, and `$keys` that were deleted. Extensions can listen to this event to perform any necessary cleanup.
306+
268307
### Admin Search
269308

270309
The admin dashboard has a search bar that allows you to quickly find settings and permissions. If you have used the `Admin.settings` and `Admin.permissions` extender methods, your settings and permissions will be automatically indexed and searchable. However, if you have a custom setting, or custom page that structures its content differently, then you must manually add index entries that reference your custom settings.

docs/extend/update-2_0.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ There have been many changes to the core frontend codebase, including renamed or
163163
* `app.extensionData` has been removed. You must now use the `Admin` extender to register settings, permissions and custom extension pages.
164164

165165
##### <span class="notable">Notable</span>
166+
* A **Reset Settings** button is now available on extension admin pages. For extensions using the standard `Admin.setting()` extender, the button appears automatically alongside the save button. **If your extension has a custom settings page, you should add the reset button yourself** by calling `this.resetButton()` in your `content()` method. Pass a label as the third argument to `this.setting()` so the modal can display human-readable names for each key:
167+
168+
```js
169+
content() {
170+
const myValue = this.setting('acme.my_key', '', app.translator.trans('acme.admin.my_key_label'));
171+
172+
return (
173+
<Form>
174+
{/* ... your form fields ... */}
175+
<div className="Form-group Form-controls">
176+
{this.submitButton()}
177+
{this.resetButton()}
178+
</div>
179+
</Form>
180+
);
181+
}
182+
```
183+
184+
Confirming the reset deletes the listed setting rows from the database and reloads the page, reverting them to their PHP-side defaults. A `Flarum\Settings\Event\Reset` event is dispatched on the backend with the `$actor`, `$extensionId`, and `$keys` involved. See the [Reset Settings Button](./admin.md#reset-settings-button) documentation for full details.
166185
* The admin sidebar navigation has been overhauled. Extension categories are now collapsible groups with count badges and category icons. Categories start collapsed by default, and searching auto-expands categories with matching results. The active extension's category is pre-expanded on page load. Extensions should declare their category in `composer.json` under `extra.flarum-extension.category`. See the [Extension Categories](./admin.md#extension-categories) section in the admin docs for the full list of available categories and how to register custom ones.
167186
* All forum pages now use the same page structure through the new `PageStructure` component. You should use this component in your extension if you are creating a new forum page.
168187
* A `HeaderDropdown` component has been added which is used for the `NotificationsDropdown` and `FlagsDropdown` your component should extend that instead of the `NotificationsDropdown`. Along with it has been also added the following components: `HeaderList` and `HeaderListItem`.

0 commit comments

Comments
 (0)