November Happy Hour will be moved to Thursday December 5th.

How do I remove or hide the Customized Search block type from editors

Vote:
 

I noticed that the block type Customized Search is available for all editors and I do not want my editors to use that block type.

How do I hide or delete it?

#197225
Sep 26, 2018 12:49
Vote:
 

I think that you can just create an initializationmodule, find the contenttype(using ContentTypeRepository) and set IsAvailable to false and save it.

#197227
Edited, Sep 26, 2018 13:20
Vote:
 

Thanks Josef, it worked.

I added a module like this

[InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class DisableBuiltInContentTypesInitializationModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
            var customizedSearchBlock = contentTypeRepository.Load<CustomizedSearchBlock>();
            if (customizedSearchBlock != null && customizedSearchBlock.IsAvailable)
            {
                var clone = customizedSearchBlock.CreateWritableClone() as ContentType;
                clone.IsAvailable = false;
                contentTypeRepository.Save(clone);
            }
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }
#197229
Sep 26, 2018 13:49
Vote:
 

We have removed it as well. The "issue" has been around for a long time:

https://world.episerver.com/blogs/Sergey-Vorushilo/Dates/2015/7/customized-search-block-in-episerver-find/

#197238
Sep 26, 2018 17:54
Vote:
 

oh God, ServiceLocator.. ;)

#197287
Sep 27, 2018 21:25
Vote:
 

Yes Valdis master of DI, please show me how to do it in a init module without that ;-)

I will buy you a beer if you show me....

#197293
Sep 28, 2018 7:12
Vote:
 

Oh, I actualy can! Well it still somehow uses the servicelocator, but should still be more correct

[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class DisableBuiltInContentTypesInitializationModule : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        var contentTypeRepository = context.Locate.Advanced.GetInstance<IContentTypeRepository>();
        var customizedSearchBlock = contentTypeRepository.Load<CustomizedSearchBlock>();
        if (customizedSearchBlock != null && customizedSearchBlock.IsAvailable)
        {
            var clone = customizedSearchBlock.CreateWritableClone() as ContentType;
            clone.IsAvailable = false;
            contentTypeRepository.Save(clone);
        }
    }

    public void Uninitialize(InitializationEngine context)
    {
    }
}

So the important part her, according to Quan Mai if I remember right, is to use the context to get get servicelocator to get the instance... wonder why that is important

#197304
Edited, Sep 28, 2018 15:48
Vote:
 

I'm just trolling you guys, sorry. btw, `context.Locate.Advanced` is just a hideout for the ServiceLocator :)

but you got me hooked. i''ll look for a way to do this with DI.

at the end... free beer is free beer!!

#197314
Sep 29, 2018 6:01
Vote:
 

And a quick fix (before you implement the code to hide it in your next sprint :D) to hide it, is to login to admin view:

Content types tab -> under block types -> click: customized search

  • click settings
  • uncheck 'Available in edit view'
  • click 'Save'
#197329
Edited, Sep 30, 2018 18:19
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.