Preferences

This section will go over how to utilize the preferences values you have defined.

Preference Interface

This section will go over the \Anomaly\PreferencesModule\Preference\Contract\PreferenceInterface class.

PreferenceInterface::field()

The field method returns the field type instance for the value or null if the value's field no longer exists.

Returns: \Anomaly\Streams\Platform\Addon\FieldType\FieldType or null
Example
$setting = $settings->get('anomaly.module.files::max_parallel_uploads');

if ($field = $setting->field()) {
    echo $field->getValue();
}

Preference Repository

This section will go over the \Anomaly\PreferencesModule\Preference\Contract\PreferenceInterface class.

PreferenceRepositoryInterface::get()

The get method returns the preference instance.

Returns: \Anomaly\PreferencesModule\Preference\Contract\PreferenceInterface
Arguments
Key Required Type Default Description
$key true string none The preference key.
Example
$max = $settings->value('anomaly.module.files::max_parallel_uploads');

echo $max->getValue();
PreferenceRepositoryInterface::get()

The get method returns the preference instance.

Returns: \Anomaly\PreferencesModule\Preference\Contract\PreferenceInterface
Arguments
Key Required Type Default Description
$key true string none The preference key.
Example
$max = $settings->value('anomaly.module.files::max_parallel_uploads');

echo $max->getValue();
PreferenceRepositoryInterface::set()

The set method allows you to set a preference value.

**Note:** Values are passed through the preference's field **modifier**.
Returns: boolean
Arguments
Key Required Type Default Description
$key true string none The preference key.
$value true mixed none The preference value.
PreferenceRepositoryInterface::value()

The value method returns the value as the preference field type normally would with getType.

Returns: mixed
Arguments
Key Required Type Default Description
$key true string none The preference key.
$default false mixed null The preference value.
Example
$value = $settings->value('anomaly.module.files::max_parallel_uploads', 5);
PreferenceRepositoryInterface::presenter()

The presenter method returns the preference value's field type presenter or null if the value's field no longer exists.

Returns: \Anomaly\Streams\Platform\Addon\FieldType\FieldTypePresenter or null
Arguments
Key Required Type Default Description
$key true string none The preference key.
Example
$decorated = $settings->presenter('anomaly.module.files::max_parallel_uploads');

echo $decorated->value;