How to disable the Content Control Wrapper (edit link) for one instances

Topics: Writing modules
Nov 15, 2012 at 7:29 PM

What I'm trying to do is display a certain content item such that I can suck it down into a file to use it as an email template for a third party email distributor. As such I need to be able to hide the edit button in this one case while I want the edit button to be displayed normally for other content types. Is there any way to disable it in just this one instance? Looking at the code I was able to determine that it was adding a wrapper to the metadata on the shape and i had hoped that something like

itemShape.Metadata.Wrappers.Clear();

would work. But the wrapper is not present on the shape at this time as it get's added after .Display is called. Unfortunately I don't see any point that I can reassert control after I call .Display to remove this wrapper or prevent it from being added. Is there a hook out there for this kind of situation? Or some alternate method of displaying the shape that will prevent this bit of code from being run?

    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");
                }
            });
        }
    }
Coordinator
Nov 16, 2012 at 6:21 PM

Did you try to do it in OnDisplayed? Wrappers get rendered after the shape.

Nov 16, 2012 at 9:10 PM

That sounds like a good idea. What hook would I use to get a piece of code to run OnDisplayed? Would I make it an IShapeTableProvider?

Something like this?

    public class AntiControlWrapper : IShapeTableProvider {
        public void Discover(ShapeTableBuilder builder) {
            builder.Describe("Content").OnDisplayed(displayed => {
                if (displayed.ShapeMetadata.Name == "ModularEmail") {
                    displayed.ShapeMetadata.Wrappers.Clear();
                }
            });
        }
    }
Coordinator
Nov 16, 2012 at 9:19 PM

Yes, except that "Content" is probably not the shape that you want to describe here. This could probably be simplified to describe ModularEmail instead.

Nov 16, 2012 at 10:22 PM

Are you saying that if I pass the name of my content type to the describe method it will only apply to that type? Or how do I target it to the specific type I want to avoid collateral damage?

Coordinator
Nov 17, 2012 at 2:38 AM
Edited Nov 17, 2012 at 2:40 AM

No, not of the content type, of the shape. To target it to a specific type, look at displayed.ContentItem.ContentType.

Nov 26, 2012 at 10:07 PM

I managed to get

	public class EditLinkRemover : IShapeTableProvider {
		public void Discover(ShapeTableBuilder builder) {
			builder.Describe("Content").OnDisplayed(displayed => {
				if (displayed.Shape.ContentItem.ContentType == "ModularEmail") {
					displayed.ShapeMetadata.Wrappers.Clear();
				}
			});
		}
	}

to appear to work. As in the code executes when I debug it. And the wrappers are gone. However the edit link still displays. Is there anything between OnDisplaying and OnDisplayed?

Coordinator
Nov 26, 2012 at 10:11 PM

Follow the debugger and find out...