Placement: How to target the Media Library Picker's Parts_Title_Summary but not the main content's Parts_Title_Summary

Topics: Troubleshooting
Aug 8, 2013 at 7:22 PM
Hi everyone,

In upgrading to the new Media Library Picker, now instead of my shape hierarchy looking like this:
Fields_MediaPicker
Parts_Title_Summary
Fields_Common_Text
Now it looks like this:
Media
    Parts_Title_Summary
    Parts_Image_Summary
Parts_Title_Summary
Fields_Common_Text
I would like to target the Media's Parts_Title_Summary for elimination, but if I were to do
<Match ContentType="Xxx">
    <Place Parts_Title_Summary="-" />
</Match>
Then that would affect both, right?

Is there a way to write the placement so it only affects the media item?
Aug 15, 2013 at 8:37 AM
Yeah, I've been struggling with this one a bit too. Unsure how to get around it without diving into the core :-/
Aug 15, 2013 at 3:16 PM
Certainly because MediaLibraryPicker.cshtml uses @Display. A choice would be replacing @diplay by something more detailled which would not diplay the Media Title.
Another as I am doing actually in my theme is to have
<Match DisplayType="Summary">
<Place Parts_TitlePart="-"/>
</Match>
and assume for each Content the display of it title directly.
Sep 13, 2013 at 3:38 AM
Edited Sep 13, 2013 at 3:38 AM
Hey Geoff, did you get a solve for this?
Sep 18, 2013 at 7:29 AM
Edited Sep 18, 2013 at 7:29 AM
Me too... I have this problem...
Sep 18, 2013 at 5:22 PM
Samuel and Nicola, I ended up deciding that I preferred the previous behavior (where the displayed form of a MediaLibraryPicker is simply an <img> tag), so I am using something like this for Fields.MediaLibraryPicker.cshtml:
@using Orchard.MediaLibrary.Fields
@using Orchard.Utility.Extensions

@{
    var field = (MediaLibraryPickerField) Model.ContentField;
    var name = field.DisplayName;
    var mediaUrl = (string) null;
    var altText = string.Empty;
    try {
        var contents = field.MediaParts.FirstOrDefault();
        if (contents != null) {
            mediaUrl = contents.MediaUrl;
            altText = contents.AlternateText;

            var contentType = (string) Model.ContentItem.ContentType;
            var displayType = (string) Model.Metadata.DisplayType;
            var combined = contentType + "-" + displayType;
            switch (combined)
            {
                // Imagine this is actually a series of content types and display types for which I have media profiles defined
                case "ContentType-DisplayType":
                    mediaUrl = Display.MediaUrl(Profile: combined, Path: mediaUrl).ToString();
                    break;
            }
        }
    }
    catch (FormatException) {}
}

<img class="media-library-picker-field media-library-picker-field-@name.HtmlClassify()" src="@mediaUrl" alt="@altText" />
Dec 5, 2013 at 4:39 AM
Geoff, I took your concept and modified it slightly so you don't need the switch statement with hard-coded content types and display types. If a profile is found matching the current content type / display type combination, then it's used, otherwise the default url is used...
@using Orchard.MediaLibrary.Fields
@using Orchard.Utility.Extensions
@using Orchard.MediaProcessing.Services;

@{
    var field = (MediaLibraryPickerField) Model.ContentField;
    var name = field.DisplayName;
    var mediaUrl = (string) null;
    var altText = string.Empty;
    try {
        var contents = field.MediaParts.FirstOrDefault();
        if (contents != null) {
            mediaUrl = contents.MediaUrl;
            altText = contents.AlternateText;

            var contentType = (string) Model.ContentItem.ContentType;
            var displayType = (string) Model.Metadata.DisplayType;
            var combined = contentType + "-" + displayType;
            var imageProfileService = WorkContext.Resolve<IImageProfileService>();
            var imageProfile = imageProfileService.GetImageProfileByName(combined);
            if (imageProfile != null) {
                mediaUrl = Display.MediaUrl(Profile: combined, Path: mediaUrl).ToString();
            }
        }
    }
    catch (FormatException) {}
}

<img class="media-library-picker-field media-library-picker-field-@name.HtmlClassify()" src="@mediaUrl" alt="@altText" />