November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi,
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 { [ViewTransformer] 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) { return; } 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; // container.Add(component); } // 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; // container.Add(component); } } } }
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.
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.
Hi,
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 :)
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:
Is that possible?