Features Service
2sxc / EAV in 9.30+ has a features management. In certain cases it would be good if the razor-view could verify that the feature is enabled - for example to show a warning when it isn't enabled yet. This is what the Features API is for.
How To Use
This example is taken from Mobius Forms and the code can be found in the Mobius Github Repo.
@{
// show warning if the save-attachments in web api isn't activated
if(!Kit.Feature.IsEnabled("SaveInAdamApi")) {
<div class="alert alert-warning">
Warning: file upload won't work yet, as it hasn't been enabled.
</div>
}
// Show warning if any of the following features are not enabled
if(!Kit.Feature.IsEnabled("PublicEditForm", "PublicUploadFiles")) {
<div class="alert alert-warning">
Warning: Edit Form and file upload have not been enabled.
</div>
}
}
The code above checks if a feature is enabled, and if not, will show a message to the viewer that this must be enabled first.
What you Need To Know
- The (new) API lies in the namespace
ToSic.Sxc.Services
- see IFeaturesService - The
IFeaturesService
will do the checks for you - ATM the public API has the following commands
Enabled(string nameId)
which checks if a feature is enabled based on the nameEnabled(string nameId, nameId)
use with more parametersEnabled(string nameId, nameId, nameId, ...)
use with as many parameters a you wantEnabled(string[] nameIds)
use with string-array
Finding Feature NameIds
As of v13 we always recommend using the NameIds since they are easier to read. These features are currently managed:
PasteImageFromClipboard
- enables paste image from clipboard in the TinyMCE editorWysiwygPasteFormatted
- enables paste formatted text in the TinyMCE editorPublicEditForm
- enables the form to open up for non-editors (to use as input dialogs) - security will still be checked based on config, so it's safePublicUploadFiles
- allows public (non-editors) to upload files (types will still be checked), so it's safeSaveInAdamApi
- enables theSaveInAdam
API in the WebAPIsPermissionCheckUsers
- enables you to set permissions for specific users (by default you can only set by standard roles like Admin, etc.)PermissionCheckGroups
- enables you to set permissions for specific groups (by default you can only set by standard roles like Admin, etc.)WebFarmCache
- enables the enterprise WebFarmCache (requires a license)
Read also
...
History
- Introduced in 2sxc 09.30
- Moved from the static object
Features
to a proper Sxc Service in v13.01 - Added nameId checks for more readable code in v13.01