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.
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?
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.
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"; } } }
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";
}
}
}
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:
Is this possible in any way? I would hate to rewrite the whole class just for this.
Hmmm, not even any suggestions on how to do it any other way?
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.
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:
By the way, sorry for not returning on this any sooner.
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:
But... there might be a better way..?
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:
and:
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?)
is working on a reply...