November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Sander Goos,
You can hide FormContainerBlock by overriding ListAvailable method of DefaultContentTypeAvailablilityService
I've made a quick demo and it works
1. Here is my custom form container block
[ContentType(GUID = "{02EC61FF-819F-4978-ADD6-A097F5BD944F}", GroupName = EPiServer.Forms.Constants.FormElementGroup_Container, Order = 4000)] [ServiceConfiguration(typeof(IFormContainerBlock))] public class CustomFormContainerBlock: FormContainerBlock { }
2. Create a custom service to get available types
using System.Collections.Generic; using System.Security.Principal; using EPiServer; using EPiServer.Core; using EPiServer.DataAbstraction; using EPiServer.DataAbstraction.Internal; using EPiServer.DataAbstraction.RuntimeModel; using EPiServer.Framework.Cache; using EPiServer.ServiceLocation; using System.Linq; namespace DebugForms_9.FormsCustomize { [ServiceConfiguration(typeof(ContentTypeAvailabilityService), Lifecycle = ServiceInstanceScope.Singleton)] public class CustomContentTypeAvailabilityService : DefaultContentTypeAvailablilityService { public CustomContentTypeAvailabilityService(ServiceAccessor<IContentTypeRepository> contentTypeRepositoryAccessor, IAvailableModelSettingsRepository modelRepository, IAvailableSettingsRepository typeSettingsRepository, GroupDefinitionRepository groupDefinitionRepository, IContentLoader contentLoader, ISynchronizedObjectInstanceCache cache) : base(contentTypeRepositoryAccessor, modelRepository, typeSettingsRepository, groupDefinitionRepository, contentLoader, cache) { } public override IList<ContentType> ListAvailable(IContent content, bool contentFolder, IPrincipal user) { var result = base.ListAvailable(content, contentFolder, user).ToList(); return result.Where(type => type.Name != "FormContainerBlock").ToList(); } public override IList<ContentType> ListAvailable(string contentTypeName, IPrincipal user) { var result = base.ListAvailable(contentTypeName, user); return result.Where(type => type.Name != "FormContainerBlock").ToList(); } } }
3. Register dependency for new service in DependencyResolverInitialization
Thanks Quan Tran,
This works perfectly.
private void ConfigureContainer(ConfigurationExpression container) { container.For<ActorsExecutingService>().Use<FormsSubmissionService>(); container.For<ContentTypeAvailabilityService>().Use<CustomContentTypeAvailabilityService>(); }
Had to register dependency like this.
Shameless own blog post boost: How to hide content types from editors in Episerver which you don’t own
You can hide the default container also with an intialization module.
I would say that the initialization module and setting the content type availability for editors is simpler and safer solution as you don't need to inherit the DefaultContentTypeAvailablilityService which is in internal namespace (and could change without any notice), used in Trans solution.
You could also remove create access rights (in admin view or in intialization module) to the content and it should hide it also from editors.
I've made a custom formcontainerblock but I still can create standard formcontainerblock from the episerver forms menu on the left side of the CMS. Can I remove this type somehow (in code not in the admin interface)?