FusionCMS is currently in an open beta state and under heavy active development.

Modules: Settings

FusionCMS provides an interface for extending system-wide settings with those from your module for usage throughout the application. Settings allow you to have control over certain aspects of FusionCMS through a helpful helper method.

Introduction

The following snippet is from FusionCMS' API settings/api.php file:

<?php

// https://github.com/fusioncms/cms/blob/master/settings/api.php

return [
    'name'        => 'API',
    'group'       => 'General',
    'icon'        => 'plug',
    'description' => 'Configure access to your websites API.',
    'settings'    => [
        'General' => [
            [
                'name'        => 'Personal Access Tokens',
                'handle'      => 'personal_access_tokens',
                'description' => 'Control whether personal access tokens are allowed or not.',
                'type'        => 'select',
                'options'     => [ 'enabled'  => 'Enabled', 'disabled' => 'Disabled' ],
                'default'     => 'disabled',
            ],
        ],
    ],
];

Let's examine what the settings file is actually doing, and where it comes into play within the Control Panel.

Overview


Settings are grouped into their respective collections (as in the settings/api.php shown above), and furthermore separated into groupings (e.g. General, Services, and Modules). The Settings overview page can be accessed from the Sidebar.

Field Description
name A string value for naming your settings.
group A string value used for group placement on the overview page.
icon FusionCMS currently uses FontAwesome.
settings array of settings grouped by tab (see Tabs).

Tabs

Now, let's turn our focus to how to create tabs for organizing your settings within the same collection. Below is a snippet of the settings/mail.php file. The snippet has been condensed for brevity. The important thing to notice is the usage of settings keys, which will become the tab names.

<?php

// https://github.com/fusioncms/cms/blob/master/settings/mail.php

return [
    'name' => 'Mail',
    ...
    'settings' => [
        'General' => [ ... ],
        'Mailgun' => [ ... ],
        'Mandrill' => [ ... ],
        'SMTP' => [ ... ],
        'Sparkpost' => [ ... ],
        'Subjects' => [ ... ],
        'Test' => [ ... ],
    ],
];

Fields

Finally, each tab can have one to many field inputs. The snippet provided below shows such a field:

    [
        'name'        => 'Personal Access Tokens',
        'handle'      => 'personal_access_tokens',
        'description' => 'Control whether personal access tokens are allowed or not.',
        'type'        => 'select',
        'options'     => [ 'enabled'  => 'Enabled', 'disabled' => 'Disabled' ],
        'default'     => 'disabled',
    ],

Field Description
name A string value used to label your field.
handle A string used to identify this specific setting value.
description A string value used to provide commentry. (optional)
type A string value that defines the field type (see Field Types below).
options An array of dropdown options. (used for select type only).
default A string value for setting a default value if no value is specified.

Field Types

Name Field Type
text Simple input field.
number Simple input field w/ number validation check.
email Simple input field w/ email validation check.
select Dropdown w/ options

Settings vs Configs

While similar to Laravel Configurations, FusionCMS Settings are rather controlled through the Control Panel and persisted in storage. This allows for easy-of-use, without having to step into code. Also, Settings come with additional features:

  • Override a config value at runtime.
  • Specify advanced settings through Vue component template.
Have questions?

We're always happy to help with code or other questions you might have. Contact support or chat live with us on Discord.

Last edited on Friday, March 26, 2021 (6 months ago)