[toc]
Contexts and widget availability
When a user edits a page in front UI, they are presented with a list of widgets in the widget browser that they can use to define the page. Widgets will be shown in this list if:
- The widget is enabled for use in the current theme type (Control Panel > System Administration > Site Administration > Widgets > Enable/Disable Widgets) or the user has the Site - Manage Settings or Site - Edit Theme permission.
- The widget's context requirements are met or the editing UI is shown in administrative edit mode (the page has been selected from the "Select Page" drop-down in the editing UI).
What are widget contexts?
Widgets define the context they require to render. For example, the Blog - Post widget always displays the current contextual blog post. It is dependent on having a blog post available to render. The Blog - Post widget, therefore, defines "Blog Post" as a required context.
The following core contexts are available and additional contexts can be defined via plugins:
Context name | Description |
Blog | A blog exists in the current context. |
Blog application page | The current page is part of the blog application (generally, this means it is within a /b/ path). |
Blog post | A blog post exists in the current context. |
Forum | A forum exists in the current context. |
Forum application page | The current page is part of the forums application (generally, this means it is within a /f/ path). |
Thread | A forum thread exists in the current context. |
User | A user exists in the current context. Note that this context requirement is not satisfied by a user being logged in. |
User file | A user file exists in the current context. |
User folder | A user folder exists in the current context. |
Group | A group exists in the current context. |
Group application page | The current page is part of a group but not a specific application. |
Message | A message exists in the current context. |
Core page | The current page is not part of a group or application. |
Conversation | A conversation exists in the current context. |
Conversations | Conversations are enabled on the site. |
Featured content | Featured content is enabled on the site. |
Wiki page (including default pages) | A wiki page exists in the current context (includes the default wiki page). |
Wiki | A wiki exists in the current context. |
Wiki application page | The current page is part of the wiki application (generally, this means the page exists in a /w/ path). |
Gallery | A media gallery exists in the current context. |
Media | A media gallery file exists in the current context. |
Media application page | The current page is part of the media gallery application (generally, this means the page exists in a /m/ path). |
Leaderboard | A leaderboard exists in the current context. |
Leaderboard application page | The current page is part of the leaderboard application (generally, this means the page exists in a /leaders/ path). |
Idea | An idea exists in the current context. |
Ideation | An ideation exists in the current context. |
Idea application page | The current page is part of the ideas application (generally, this means the page exists in a /i/ path). |
Calendar | An calendar exists in the current context. |
Calendar Event | An calendar event exists in the current context. |
Calendar application page | The current page is part of the calendar application (generally, this means the page exists in a /c/ path). |
Defining contexts required by a widget
Widgets define their required context within the widget editor (Control Panel > Administration > Site Administration > Widgets > Manage Widgets) on the Configuration tab via the Available Contexts field.
One or more contexts can be defined for a widget. If no contexts are defined, the widget is always available with respect to permissions. Otherwise, all of the defined contexts must be valid for the widget to be available.
Creating a widget context
Available contexts are defined by IScriptedContentFragmentContextProvider-based plugins. The full name of this type is: Telligent.Evolution.Extensibility.UI.Version1.IScriptedContentFragmentContextProvider and it exists within the Telligent.Evolution.ScriptedContentFragments assembly. In addition to the base IPlugin members, it adds the following:
IEnumerable<Telligent.Evolution.Extensibility.UI.Version1.ContextItem> GetSupportedContextItems()
This method should return all contexts managed by this context provider. Each ContextItem is defined using a Name and an Id. The Name is shown in the widget editing user interface and the Id is used internally to identify this context.
bool HasContextItem(System.Web.UI.Page page, Guid contextItemId)
This method should return true if the provided context identifier exists on the provided page. For unrecognized context identifiers, the provider should always return false. For recognized context identifiers, the provider should only return true if a recognized and valid object described by the context exists on the page.
For example, for a context named "Blog Example" which identifies that a widget requires that a blog exist on the current page, the associated context provider should only return true if a valid blog is in context on the current page. We can check the current page's ContextItems collection to determine if a page has a blog in context.
using System; using System.Collections.Generic; using System.Linq; using Telligent.Evolution.Extensibility.Api.Version1; using Telligent.Evolution.Extensibility.UI.Version1; using Telligent.Evolution.Extensibility.Version1; namespace Telligent.Evolution.Examples { public class BlogExampleWidgetContext : IScriptedContentFragmentContextProvider { private readonly Guid BlogExampleContextItemId = new Guid("dd61aa2a-2595-4ced-a851-0871502911a0"); IEnumerable<ContextItem> IScriptedContentFragmentContextProvider.GetSupportedContextItems() { return new List<ContextItem>() { new ContextItem("Blog Example", BlogExampleContextItemId) }; } bool IScriptedContentFragmentContextProvider.HasContextItem(System.Web.UI.Page page, Guid contextItemId) { return contextItemId == BlogExampleContextItemId && PublicApi.Url.CurrentContext.ContextItems.GetAllContextItems() .Any(item => item.ContentTypeId == PublicApi.Blogs.ApplicationTypeId); } string IPlugin.Description { get { return "Enables studio widgets to be limited to pages with an Blog Application in context"; } } void IPlugin.Initialize() { } string IPlugin.Name { get { return "Blog Example Widget Context"; } } } }