Remove the «Suggested Page Types» section when creating a new page

Vote:
 

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

#90493
Sep 10, 2014 16:23
Vote:
 

+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.

#90498
Sep 10, 2014 19:55
Vote:
 

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

#90501
Sep 10, 2014 22:59
Vote:
 

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?

#90507
Sep 11, 2014 7:21
Vote:
 

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

#90560
Sep 12, 2014 9:48
Vote:
 

Cool! But how can we inject this code into the EPI UI?

#90561
Sep 12, 2014 9:51
Vote:
 

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

#90563
Edited, Sep 12, 2014 9:59
Vote:
 

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?

#90630
Sep 15, 2014 11:59
Vote:
 

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

#90632
Sep 15, 2014 12:10
Vote:
 

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.

#139968
Edited, Oct 12, 2015 13:14
Vote:
 

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.

#140182
Oct 12, 2015 15:46
Vote:
 

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

#140551
Oct 22, 2015 15:05
Vote:
 

Hi Yannis.

I updated my post to match the alloy tech sample, hope that clarifies things

#140558
Oct 22, 2015 16:19
Vote:
 

Actually don't need a "ZeroSuggestionsContentTypeAdvisor". All you need to do is to remove all registered instances

context.Container.EjectAllInstancesOf<IContentTypeAdvisor>();

#147509
Apr 17, 2016 14:55
Vote:
 

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?

#174958
Edited, Feb 08, 2017 15:20
* 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.