Hiding standard FormContainerBlock

Vote:
 

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)?

Episerver Remove standard formcontainerblock

#195445
Edited, Jul 25, 2018 10:59
Vote:
 

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

#195481
Edited, Jul 26, 2018 6:10
Vote:
 

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.

#195483
Jul 26, 2018 9:43
Vote:
 

Great  :)

#195484
Jul 26, 2018 9:55
Vote:
 

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.

#199724
Dec 07, 2018 12:42
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.