Override Content.ControlWrapper

Topics: Customizing Orchard
Aug 19 at 1:26 AM
I've achieved what I wanted to... but I'm not happy with it :P

I wanted to present the content control wrapper for each content item to allow convenient editing for admin users. This was styled to present the button in a discrete fixed position. All good.

Several pages however, include projection elements in their layouts. These all render Summary displays but each with their own edit button. This coupled with the fixed position means we get a stack of edit buttons on top of each other. The supposedly simple solution was to only render the edit button for the Content item being displayed as Detail. No such luck.

I was trying to override Orchard.Core.Contents.ControlWrapper with a duplicate class in my own module. The closest I got however was to get my class running as well as the core one and so undoing the work the core class does as follows:

Orchards core class for the control wrapper:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Extensions;

namespace Orchard.Core.Contents {
    [OrchardFeature("Contents.ControlWrapper")]
    public class ControlWrapper : IShapeTableProvider {
        public void Discover(ShapeTableBuilder builder) {
            builder.Describe("Content").OnDisplaying(displaying => {
                if (!displaying.ShapeMetadata.DisplayType.Contains("Admin")) {
                    displaying.ShapeMetadata.Wrappers.Add("Content_ControlWrapper");
                }
            });
        }
    }
}
My module override:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.DisplayManagement.Descriptors;
using Orchard.Environment.Extensions;

namespace MyModule.Core {

    public class ControlWrapper : IShapeTableProvider {
        public void Discover(ShapeTableBuilder builder) {
            builder.Describe("Content").OnDisplaying(displaying => {
                
                displaying.ShapeMetadata.Wrappers.Clear(); // this is a hack. We're undoing work Orchard.Core.Contents.ControlWrapper has tried to do.
                
                if (displaying.ShapeMetadata.DisplayType.Contains("Detail")) {
                    displaying.ShapeMetadata.Wrappers.Add("Content_ControlWrapper");
                }
            });
        }
    }
}
Would be great to get rid of the commented line and just use my implementation if possible?