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

Henrik Fransas
Member since: 2007
 

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
  • Josef-Ottosson
    Member since: 2013
     

    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
  • Henrik Fransas
    Member since: 2007
     

    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
  • Robert Runge
    Member since: 2013
     

    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
  • valdis iljuconoks
    Member since: 2011
     

    oh God, ServiceLocator.. ;)

    #197287 Sep 27, 2018 21:25
  • Henrik Fransas
    Member since: 2007
     

    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
  • Sebbe
    Member since: 2013
     

    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
  • valdis iljuconoks
    Member since: 2011
     

    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
  • Antti Alasvuo
    Member since: 2010
     

    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