Preferences

Preferences values are powered entirely by field types. This section will go over the basics of defining, managing, and using preferences for addons.

Preferences Keys

Preferences values are defined by a key. The key is simply the dot namespace of the addon and the preferences field slug.

anomaly.modules.files::parallel_uploads

Defining Preferences

Preferences are defined using field definitions located in the addon's resources/config/preferences.php file:

<?php

return [
    'max_parallel_uploads' => [
        'type'     => 'anomaly.field_type.integer',
        'required' => true,
        'config'   => [
            'default_value' => 3,
            'min'           => 1,
        ],
    ],
];

Note: Any fields requiring a pivot table or multiple columns will not work properly - notably the Image Field Type.

Defining Form Sections

You can also quickly define form sections the same as fields. To define sections move your resources/config/preferences.php file to resources/preferences/preferences.php and include a resources/preferences/sections.php file to define sections. The sections.php file simply returns an array of section definitions:

<?php

return [
    'details'      => [
        'context' => 'info',
        'title'   => 'streams::label.details',
        'fields'  => [
            'name',
            'description',
        ],
    ],
];

Displaying Preferences Forms

Preferences can be set by API just like any other Stream entry however you may want to display a settings form.

To get started you can extend or inject the \Anomaly\PreferencesModule\Preference\Form\PreferenceFormBuilder class. The entry value for configuration form builders are the addon's dot namespace and the user is detected automatically:

use \Anomaly\PreferencesModule\Preference\Form\PreferenceFormBuilder;

public function edit(PreferenceFormBuilder $builder)
{
    return $builder->render('anomaly.module.files');
}
**Pro Tip:** The preferences form builder is not much different than any other form builder so go crazy and extend or customize as needed in your own project.