How to override Content.SummaryAdmin.cshtml in Orchard.Core

Topics: Customizing Orchard
Dec 8, 2014 at 8:25 AM
Hi

I have create a content part. I doesn't want to render edit and delete link in Contnt.SummaryAdmin, When the contentitem with my contentpart after publised.
After approval workflow, I will modify the flag, to render these two link.

in Content.SummaryAdmin.cshtml, I add:
var docPart = ((ContentItem)Model.ContentItem).As<DocumentPart>();
bool isUnderApprove = false;
if (null!=docPart && docPart.Status.Equals("APV"))
{
    isUnderApprove = true;
}
...
    @if (Authorizer.Authorize(Permissions.EditContent, contentItem) && !isUnderApprove)
    {
        @Html.ItemEditLink(T("Edit").Text, contentItem)@T(" | ")
    }
    @if (Authorizer.Authorize(Permissions.DeleteContent, contentItem) && !isUnderApprove)
    {
        @Html.Link(T("Delete").Text, Url.ItemRemoveUrl(contentItem, new {returnUrl}), new {itemprop = "RemoveUrl UnsafeUrl"})
    }
I have created a Theme base on TheThemeMachine. And I have created a ThemeSelecto
public class GWtecThemeAdmin : IThemeSelector
{
    public ThemeSelectorResult GetTheme(RequestContext context)
    {
        if (AdminFilter.IsApplied(context))
        {
            return new ThemeSelectorResult { Priority = 100, ThemeName = "GWtecTheme" };
        }

        return null;
    }
}
It Ok, but the layout of Admin is error. I doesnt' want to override all Admin theme, but just to hide the two link ( edit and delete).

How to do ?

Thanks!
Dec 8, 2014 at 11:30 AM
Edited Dec 8, 2014 at 11:31 AM
I think you can use IShapeTableProvider. You have to use the 'Describe' function and provide the alternate view for your buttons (edit/delete).

Give a try to following link, it might help you:
http://weblogs.asp.net/bleroy/orchard-shapeshifting
Marked as answer by ezrachen on 12/8/2014 at 5:45 AM
Dec 8, 2014 at 12:46 PM
Hi TahirRauf

Very good idea. But I have another problem. If I put the ContentShapeProvider in my content part module. Can I put the alternate template in content part module's views
folder ? How to naming the alternate template ?

Thanks!
Dec 8, 2014 at 1:28 PM
Yes you can keep the alternate file in your Content Part's Views folder.
No problem in naming the alternate. Just pick a name and make a view in the Views folder.
You can keep file in main Views folder or any sub-folder.
E.g Make a view named as "HideEditDeleteButton.cshtml" in the Views folder and give the path in your Describe function as :

displaying.ShapeMetadata.Alternates.Add("HideEditDeleteButton");
Dec 8, 2014 at 1:48 PM
Hi TahirRauf

How to Describe the Content.SummaryAdmin's shapeType in ContentShapeProvider ? Are there document about all orchard 's shapetype ?

Thanks! Best Regards!
Dec 8, 2014 at 1:58 PM
I think its simply Describe("Content_SummaryAdmin").

Meanwhile following might help you:

http://www.szmyd.com.pl/blog/customizing-orchard-shapes#.T1Tm-BmgA64

Regards!
Dec 8, 2014 at 2:06 PM
Hi TahirRauf

I have tried: But it doesn't work. "Content_SummaryAdmin" no callback. The other, can I remove original Alternates ? Or how to assign priority on there alternates ?
    public void Discover(ShapeTableBuilder builder)
    {
        builder.Describe("Content_SummaryAdmin").OnDisplaying(displaying =>
        {                
            if (displaying.ShapeMetadata.DisplayType == "SummaryAdmin")
            {
                var docPart = ((ContentItem)displaying.Shape.ContentItem).As<DocumentPart>();
                if (null != docPart)
                {
                    if (docPart.Status == "APV")
                    {
                        displaying.ShapeMetadata.Alternates.Add("Items_GWtec_DocManager_SummaryAdmin");
                    }
                }
            }
        });
    }
Dec 10, 2014 at 9:08 AM
Hi Everybody

I have tried. It is OK! Orchard, very good, very flexibility.
    public void Discover(ShapeTableBuilder builder)
    {
        builder.Describe("Content").OnDisplaying(displaying =>
        {                
            if (displaying.ShapeMetadata.DisplayType == "SummaryAdmin")
Dec 10, 2014 at 12:55 PM
Hi Everybody

I can add alternate. But the alternate is not use when rendering. For original alternates have high priority. How to do ?

Thanks!
Dec 11, 2014 at 12:30 AM
Hi Everybody

I have solved the problem: displaying.ShapeMetadata.OnDisplaying()

namespace GWtec.DocManager.ShpaeProviders
{
public class DocumentPartShapeProvider : IShapeTableProvider
{
    private readonly IWorkContextAccessor _workContextAccessor;

    public DocumentPartShapeProvider(IWorkContextAccessor workContextAccessor)
    {
        _workContextAccessor = workContextAccessor;
    }

    public void Discover(ShapeTableBuilder builder)
    {
        builder.Describe("Content").OnDisplaying(displaying =>
        {                
            if (displaying.ShapeMetadata.DisplayType == "SummaryAdmin")
            {
                var docPart = ((ContentItem)displaying.Shape.ContentItem).As<DocumentPart>();
                if (null != docPart)
                {
                    if (docPart.Status == "APV")
                    {
                        displaying.ShapeMetadata.OnDisplaying(display =>
                            {
                                display.ShapeMetadata.Alternates.Clear();
                                display.ShapeMetadata.Alternates.Add("GWtec_DocManager_ContentSummaryAdmin");
                            });
                    }
                }
            }
        });
    }
}
}