When I'm adding a new Discount to a Campaign in the new promotions UI.. is there any way to hide the "Suggested Types" section on that screen?
Here is a good blog on how you can modify the "Suggest Types" section, including hiding it completely.
This would remove the "Suggested Types" section for all types of content, though. That might be a plus on the side - but it is worth to mention.
I guess you can maybe configure your own ContentTypeAdvisor and do some logic there to not show suggestions if the content is children of the campaign root or something?
That's a good point Joel, such modifications will affect the "Suggested Types" for all content types. To only remove it for some types you would as you say have to implement your own IContentTypeAdvisor, and vary the logic depending on the type of the parent IContent that is supplied to the GetSuggestions method.
Good advice, thank you both!
I've implemented a custom IContentTypeAdvisor that does what I need.
To configure my site to use it:
container.Configure(x => x.For<IContentTypeAdvisor>().Use<CustomContentTypeAdvisor>());
But, is there a way to replace only the DefaultContentTypeAdvisor? I don't want to eject all of them - I only want to replace the default with my custom implementation. Can it be done?
Bump.. any ideas?
I'm not sure exactly how to do that, I've never had the need to do it. I would suggest looking into StructureMap for more information about how to do more explcit configuration, as we just use that to handle dependency injection (the container object is a type from StructureMap).
However, I'm curious, why do you just want to remove a specific one? Because ejecting all and then adding yours will remove the default one from the system and yours will be used instead. I doubt we even support calling multiple IContentTypeAdvisors, I suspect only the one that is the registered as default in the container will be called.
If you want to replace an existing service, but still have access to an instance of the replaced one, I would suggest using the Intercept pattern. You can read about it here, http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Initialization/dependency-injection/.
Ah, thanks. To clear things up:
- I had believed that Epi was using two implementations of IContentTypeAdvisor, because I noticed there are 2 built-in types (CatalogContentTypeAdvisor + DefaultContentTypeAdvisor).
- I was concerned about replacing both of those with one custom implementation...
- But I dug into the source code --- and I found that CatalogContentTypeAdvisor uses an instance of DefaultContentTypeAdvisor internally.
- So I decided to follow a similar pattern: my custom implementation will use CatalogContentTypeAdvisor internally:
public class CustomContentTypeAdvisor : IContentTypeAdvisor
private readonly CatalogContentTypeAdvisor _catalogContentTypeAdvisor;
public CustomContentTypeAdvisor(CatalogContentTypeAdvisor catalogContentTypeAdvisor)
_catalogContentTypeAdvisor = catalogContentTypeAdvisor;
public IEnumerable<int> GetSuggestions(IContent parent, bool contentFolder, IEnumerable<string> requestedTypes)
// To disable the "Suggested Content Types" functionality for Promotions in Episerver:
if (parent is SalesCampaign)
return new List<int>();
// For other content, use Epi's implementation:
return _catalogContentTypeAdvisor.GetSuggestions(parent, contentFolder, requestedTypes);
Ah, right gotcha.
Glad that you got it working.