Display() of Driver is not getting called

Topics: Customizing Orchard
Feb 12, 2015 at 7:31 AM
Driver code

[UsedImplicitly]
public class PopupPartDriver : ContentPartDriver<PopUpPart>
{
    private readonly IOrchardServices _services;

    public PopupPartDriver(IOrchardServices services)
    {
        _services = services;
    }

    protected override DriverResult Display(PopUpPart part, string displayType, dynamic shapeHelper)
    {
        PopUpPart popup = new PopUpPart() { Text = ReadXML()};

        return ContentShape("Parts_DisplayPopup", () => shapeHelper.Parts_DisplayPopup(PopupData: popup.Text));
    }

    private List<string> ReadXML()
    {
        List<string> strXMLtext = new List<string>();
        string filePath = ConfigurationManager.AppSettings["XMLFilePath"];
        FileInfo fi = new FileInfo(filePath);
        if (fi.Exists)
        {

            XmlTextReader reader = new XmlTextReader(filePath);
            //PopUpPart part;
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Text:
                        strXMLtext.Add(reader.Value);
                        break;
                }
            }
        }
        return strXMLtext;
    }
}
And Handler Code
public Localizer T { get; set; }
    public DisplayPopUpPartHandler()
    {
        Filters.Add(new ActivatingFilter<PopUpPart>("Site"));
        Filters.Add(new TemplateFilterForPart<PopUpPart>("PopUp", "Parts/DisplayPopup", "displaypopups"));
    }

    protected override void BuildDisplayShape(BuildDisplayContext context)
    {
        base.BuildDisplayShape(context);
    }

    protected override void GetItemMetadata(GetContentItemMetadataContext context)
    {
        if (context.ContentItem.ContentType != "Site")
            return;
        base.GetItemMetadata(context);
        context.Metadata.EditorGroupInfo.Add(new GroupInfo(T("Pop Up")) { Id = "Display Popups" });
    }      

What wrong I have done, display() of Driver is not getting called only constructor gets called
Feb 12, 2015 at 10:29 PM
Your handler is wrote as for a part that would be used in the site settings. Your ActivatingFilter() means that your part will be activated with the "Site" content type, the type used for dashboard site settings. Your TemplateFilterForPart() defines a template view (DisplayPopup.cshtml) that you have to put in your Views/EditorTemplates/Parts module folder. Finally, your GetItemMetadata() means that you want in the site settings menu a sub group named "Pop Up"...

So, in this context, in your driver you can only override the Editor() methods

Enable and see the Comments module code. In CommentSettingsPartHandler.cs you will see the same kind of code. In CommentSettingsPartDriver.cs, add a Display() method and put some breakpoints, you will see that, when you go to the comments setting, the Editor() methods are called, but not the Display() one

If you want a part that can be attachable to other content types and displayed in the front end, it depends what is your current "PopUpPart". If it's really a part used for settings, then you have to write another part that maybe will use these settings. See in the Orchard source how such a part is coded. Otherwise, you have to change your current part handler code

Regards
Feb 13, 2015 at 4:47 AM
Thank you jtkech...

your explanation helped me to understand more than my expectation...

I planned to develop a module, where pop up would come only once on home page with all recent changes made. This would be stored in an XML file. I must read and show it as pop up.

Can you give me any tips to accomplish this.
Feb 13, 2015 at 7:09 AM
Maybe different ways. Is an xml file a constraint for you ? Do you want a setting for your xml file path (in place of a web.config setting) ? Some parts of the problem can be done via the dashboard without coding, but you are talking about a module... Anyway, at the end you will need an alternate view that will use a script (e.g a jQuery plugin) to render your pop up view that will use your xml data...

If you want to do it all by code, send me an email via my codeplex profile. Right now I have to stop working, but I will see your email tomorrow. Then, depending on the solution that we will choose, I will be able to share with you some sample files as a starting point

Regards
Feb 13, 2015 at 8:23 AM
Sent email,

First solution is also fine for me!!!!