Table of Contents

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

  1. The (new) API lies in the namespace ToSic.Sxc.Services - see IFeaturesService
  2. The IFeaturesService will do the checks for you
  3. ATM the public API has the following commands
    1. Enabled(string nameId) which checks if a feature is enabled based on the name
    2. Enabled(string nameId, nameId) use with more parameters
    3. Enabled(string nameId, nameId, nameId, ...) use with as many parameters a you want
    4. Enabled(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:

  1. PasteImageFromClipboard - enables paste image from clipboard in the TinyMCE editor
  2. WysiwygPasteFormatted - enables paste formatted text in the TinyMCE editor
  3. PublicEditForm - 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 safe
  4. PublicUploadFiles - allows public (non-editors) to upload files (types will still be checked), so it's safe
  5. SaveInAdamApi - enables the SaveInAdam API in the WebAPIs
  6. PermissionCheckUsers - enables you to set permissions for specific users (by default you can only set by standard roles like Admin, etc.)
  7. PermissionCheckGroups - enables you to set permissions for specific groups (by default you can only set by standard roles like Admin, etc.)
  8. WebFarmCache - enables the enterprise WebFarmCache (requires a license)

Read also

...

History

  1. Introduced in 2sxc 09.30
  2. Moved from the static object Features to a proper Sxc Service in v13.01
  3. Added nameId checks for more readable code in v13.01