Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan Christoffersen 64 posts 119 karma points
    Jun 02, 2010 @ 13:25
    Dan Christoffersen
    0

    Is there an easy way to extend the ContentPicker datatype?

    What we are trying to achieve is just a simple improvement to the ContentPicker datatype where instead of only the name of the node selected is displayed, the full path to the node is shown.

    I was thinking that there must be a way to extend the ContentPicker class. Something like this:

    ...
    public class ImprovedContentPicker : ContentPicker
    {
    ...
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
    base.Render(writer);
    ...
    (my new code)
    }

    Is this possible in any way? I would hate to rewrite the whole class just for this.

     

  • Dan Christoffersen 64 posts 119 karma points
    Jun 07, 2010 @ 13:29
    Dan Christoffersen
    0

    Hmmm, not even any suggestions on how to do it any other way?

  • Lee Kelleher 3951 posts 15238 karma points MVP 11x admin c-trib
    Jun 07, 2010 @ 13:53
    Lee Kelleher
    0

    Hi Dan,

    Yes, inheriting the ContentPicker class and overriding the Render would work fine.  I'd go about it the same way - like you say, there's no point in rewriting the entire class to change a small bit of (presentation) functionality.

    Did you run into any problems when you tried this?

    Cheers, Lee.

  • Dan Christoffersen 64 posts 119 karma points
    Jun 30, 2010 @ 11:46
    Dan Christoffersen
    0

    Do I need to do anything but copy the .dll to the bin directory? Anywhere i should register the new datatype?

    Basically all i do is this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.controls;
    
    namespace RoskildeDomkirke
    {
        public class ImprovedContentPicker : ContentPicker
        {
    
      protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
            // do something new
                base.Render(writer);
            }
    
    
        }
    }

    By the way, sorry for not returning on this any sooner.

  • Steen Tøttrup 191 posts 291 karma points c-trib
    Jun 30, 2010 @ 11:56
    Steen T√łttrup
    0

    Uhm, I would think that you would have to create a new data type (in the Umbraco UI) using the new improved content picker, but to do that, you would probably have to give it a new name and a new id (guid?).

    I don't think there's any way around making a new data type like this:

    public class ImprovedContentPickerDataType : BaseDataType, IDataType {

    public override IDataEditor DataEditor {
    get { if (editor == null) { editor = new ImprovedContentPicker(this.Data); }
    return editor;
    }
    }
    public override Guid Id {
    get {
    return // TODO: Some new Guid;
    }
    }

    public override string DataTypeName {
    get {
    return "Improved Content Picker";
    }
    }
    }

     

    But... there might be a better way..?

  • Dan Christoffersen 64 posts 119 karma points
    Jun 30, 2010 @ 14:06
    Dan Christoffersen
    0

    Thanks Steen, that helped a lot. I was missing the new data type as you pointed out.

    However, I ended up extending that as well from umbraco.editorControls.pagepicker.PagePickerDataType.

    If anyone's interested, this is the two classes used:

        public class ImprovedContentPickerDataType : umbraco.editorControls.pagepicker.PagePickerDataType
        {
    
            ImprovedContentPicker editor;
    
            public override IDataEditor DataEditor
            {
                get
                {
                    if (editor == null) 
                    { 
                        editor = new ImprovedContentPicker(this.Data); 
                    }
                    return editor;
                }
            }
            public override Guid Id
            {
                get {
                    return new Guid("59ea5720-8434-11df-8395-0800200c9a66");
                }
            }
    
            public override string DataTypeName
            {
                get
                {
                    return "Improved Content Picker";
                }
            }
    
        }

    and:

        public class ImprovedContentPicker : pagePicker
        {
    
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
    
                string tempTitle = umbraco.library.NiceUrl(int.Parse(this.Value));
                writer.WriteLine("<div>Link: <a href='" + tempTitle + "' target='_blank'>" + tempTitle + "</a></div>");
                base.Render(writer);
            }
    
            public ImprovedContentPicker (IData data)
                : base(data)
            {
            }
    
    
        }
  • aditya 6 posts 26 karma points
    Feb 15, 2012 @ 07:03
    aditya
    0

    hey when tried this but got compile time error. 

    Error1The type or namespace name 'editorControls' does not exist in the namespace 'umbraco' (are you missing an assembly reference?)

    i have passed the reference of this editorControls.
Please Sign in or register to post replies

Write your reply to:

Draft