Try our conversational search powered by Generative AI!

Gadget automatically added for all users


I would like two gadgets (none of witch are a part of my code base) to be added as default (left pane, below page tree) for all users:

  • The Versions gadget
  • The LanguageManager gadget (Episerver.Labs.LanguageManager)

Is that possible?

May 06, 2018 23:01


Yes you can do that by implementing an IViewTransformer and add the components if they haven't been added already.

A disclamer. I have not compiled the code after I added the LanguageManager code.

using System.Linq;
using System.Security.Principal;
using EPiServer.Cms.Shell.UI.Components;
using EPiServer.Shell;
using EPiServer.Shell.ViewComposition;
using EPiServer.Labs.LanguageManager;

namespace Alloy.Sample.Business.Initialization
    public class DefaultComponentsTransform : IViewTransformer
        private readonly IComponentManager _manager;

        public DefaultComponentsTransform(IComponentManager manager)
            _manager = manager;

        public int SortOrder => 300;

        public void TransformView(ICompositeView view, IPrincipal principal)
            var container = view.RootContainer.FindContainerByPlugInArea(PlugInArea.Navigation);
            if (container == null)

            var exist = container.Components.Any(c => c.DefinitionName == typeof(VersionsComponent).FullName);
            if (!exist)
                var definition = _manager.GetComponentDefinition(typeof(VersionsComponent).FullName);
                var component = definition.CreateComponent();
                component.SortOrder = 500; //


            // LanguageManager inherits from ComponentDefinitionBase which has a CreateComponent() method so there should be no need to
            // get the definition from the IComponentManager
            exist = container.Components.Any(c => c.DefinitionName == typeof(LanguageManagerComponent).FullName);
            if (!exist)
                var definition = _manager.GetComponentDefinition(typeof(VersionsComponent).FullName);
                var component = new LanguageManagerComponent().CreateComponent();
                component.SortOrder = 510; //

May 07, 2018 13:29

Very enlightening, thank you.

How can it be that even if a component/gadget is removed from the UI the container still holds that component?

For instance if I add a component i under navigation or assets, then remove it a reloads page, the component is still present in the above code.

May 15, 2018 15:39

The solution by Magnus seems to have a little problem. If the user has specifically chosen to remove the components his setting will override the code, i.e. the components will not be (re-)added. Is there a way to 'override the override', i.e. to make sure that the components are always added?

NB. The mentioned user setting appears to be saved in the server database, but is not accessible via IProfileRepository.

May 16, 2018 14:51

The personalized settings are stored in the DDS.
And it works something like this.
1. We have a HomeView with a default config
2. When it is created we run all view configurations based on the sortOrder
3. We have an internal PersonalizationViewTransformer than takes applies the settings stored for the current user
So depending on when your view transformation run you will have different values in the containers.

If you e.g always want to add the Version component, even though the user has removed it, you need to have a sortOrder
that is higher than the sort order of out PersonalizationViewTransformer, which right now have the magic number of 10000.

When I test to set 10001 for the sort order of the example above I noticed that we have a bug :(. I have reported a bug for it.
It will re-add the removed component, but you get an error in the console.

And I suggest that you honor the Editors decision. If they have removed the component, they probably do not want it :)

May 25, 2018 8:05

Hi Magnus!
I tried adding the component with SortOrder = 10001, but it does not get added.
However. if I add it manually it is now added twice..
Best regards,

May 28, 2018 10:39
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.