+1
Never liked this feature. We always try to reduce the number of template you can choose from, and it would look much more tidy without the "Suggested Page Types" section.
There seems to be an Ajax call similar to /EPiServer/cms/Stores/contenttype/?query=getsuggestedcontenttypes&parentReference=4048_4124&requestedTypes=episerver.core.pagedata, which is handled by EPiServer.Cms.Shell.UI.Rest.ContentTypeStore.GetSuggestedContentTypes. I guess the best approach would be to avoid making this call in the first place... But how O_o
Yeah, maybe.
We now alot of control when it comes to altering the CMS itself through it's .js files, but by altering the code I might break something?
Hi,
Please try this client approach:
var registry = epi.dependency.resolve("epi.storeregistry");
var contentTypesStore = registry.get("epi.cms.contenttype");
require(["dojo/_base/lang", "dojo/aspect"], function(lang, aspect) {
aspect.around(contentTypesStore, "query", function(originalMethod) {
return function(query, options) {
if(lang.isObject(query) && query.query === "getsuggestedcontenttypes") {
return [];
}
return originalMethod(query, options);
};
});
});
Hope that help!
// Ha
Hi Johan,
Simplest way, you can put the code directly into Chrome's console.
Some formal ways:
1. http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Framework/7/Add-Ons/Add-ons/
2. http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Framework/7/Client-Resources/Client-Resources/
// Ha
I first tried injecting this into the console but I believe this code has to be executed on page load, right? So injecting it into the browser will prolly be too late?
Oh yes, inject in chrome's console just for test, if ok I think we need to create an add-on and then insert code into the add-on client initialize module like this:
define([
// dojo
"dojo/_base/declare",
"dojo/_base/lang",
"dojo/aspect",
// epi
"epi",
"epi/_Module",
"epi/routes"
],
function (
// dojo
declare,
lang,
aspect,
// epi
epi,
_Module,
routes
) {
return declare([_Module], {
initialize: function () {
// summary:
// Initialize module
this.inherited(arguments);
// Patch episerver
this._removeSuggestedTypes();
},
_removeSuggestedTypes: function () {
// summary:
// Return an empty array to hide the suggested types when create new content.
// tags:
// private
var registry = epi.dependency.resolve("epi.storeregistry");
var contentTypesStore = registry.get("epi.cms.contenttype");
aspect.around(contentTypesStore, "query", function (originalMethod) {
return function (query, options) {
if (lang.isObject(query) && query.query === "getsuggestedcontenttypes") {
return [];
}
return originalMethod(query, options);
};
});
}
});
});
// Ha Bui
The most correct approach would probably be to avoid making the request in the first place, I haven't investigated that way of doing it though.
What I do know is this - A GET request is made to ContentTypeStore (in EPiServer.Cms.Shell.UI.Rest).
In the class constructor it accepts a few arguments, one being a list of IContentTypeAdvisor, an interface that exposes a single method, GetSuggestions.
From the somewhat quick examination I did, the interface is only being referenced from ContentTypeStore, and implemented by DefaultContentTypeAdvisor.
This solution should probably do what you want..
Implement IContentTypeAdvisor
public class ZeroSuggestionsContentTypeAdvisor : IContentTypeAdvisor { public IEnumerable<int> GetSuggestions(IContent parent, bool contentFolder, IEnumerable<string> requestedTypes) { return Enumerable.Empty<int>(); } }
Remove the previously added implementations, and add the new one
(Like I said, the ContentTypeStore accepts a list of IContentTypeAdvisor in its construtor, so simply registering the new one wont make a difference)
The following method can be found in the AlloyTech sample, DependencyResolverInitialization class
public void ConfigureContainer(ServiceConfigurationContext context) { context.Container.EjectAllInstancesOf<IContentTypeAdvisor>(); context.Container.Configure(ConfigureContainer); DependencyResolver.SetResolver(new StructureMapDependencyResolver(context.Container)); } private static void ConfigureContainer(ConfigurationExpression container) { container.For<IContentRenderer>().Use<ErrorHandlingContentRenderer>(); container.For<ContentAreaRenderer>().Use<AlloyContentAreaRenderer>(); container.For<IContentTypeAdvisor>().Use<ZeroSuggestionsContentTypeAdvisor>(); }
Hope that it helps!
Edit: Updated code regarding removing and adding implementations to match the AlloyTech sample.
Nice solution Kim. There should really be a setting somewhere instead. This function is so stupid, unless it's super smart implemented, which it isn't. E.g. it doesn't make sense two display two suggested content types when there's only two available in total.
@Kim and whomever made it work,
Hi, I followed the latter advice and managed to get the ZeroSuggestionsContentTypeAdvisor firing in the code but I cannot find a suitable initaliser place that I can set the second method (ConfigureContainer). How did you make it execute?
Hi Yannis.
I updated my post to match the alloy tech sample, hope that clarifies things
Actually don't need a "ZeroSuggestionsContentTypeAdvisor". All you need to do is to remove all registered instances
context.Container.EjectAllInstancesOf<IContentTypeAdvisor>();
Thanks Alf, that simple solution did the trick.
I agree with the suggestion that we should have more control over this though. I had a scenario where only 2 page types were allowed, but when creating the page it was actually showing 4 in the dialog because of the suggestions.
Maybe it should only show the suggestions if there are > 10 page types available?
Hi.
Is it possible to remove the section called «Suggested Page Types» when creating a new page? When there's few available pagetypes I find it redundant to show the «Suggested Page Types» section, because it looks like there are duplicate page types available.
Does anyone know how to do this through configuration or code?
// Anders