Extending macro datatype Options
jHodgkinson
Posted: Tuesday, January 08, 2008 3:18:50 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
I've created my own datatype in umbraco... how can I expose it so that it can be used as a macro datatype option?
jHodgkinson
Posted: Tuesday, January 08, 2008 3:26:29 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
I also want to be able to drop multiple instances of this macro on the same page so I don't believe a new document type would work. If I'm wrong in my assumptions, please let me know... thx in advance!
mortenbock
Posted: Tuesday, January 08, 2008 5:14:50 PM

Rank: Addict

Joined: 7/19/2006
Posts: 733
Location: Århus, Denmark
Unfortunately the datatypes and the macro parameter types are not the same, and as far as I have been told, it is not a easy task to create a new macro parameter type, as you would need to modify the source for that purpose.

What are you ultimately trying to achieve? Maybe there is another way to get it done?

I'm looking for a new job

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

jHodgkinson
Posted: Tuesday, January 08, 2008 6:50:46 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
thanks Morton - that was along the lines of what I was thinking since it was not an obvious option... basically I want to have one of my datatypes available as a macro option to help normalize available options and make it easier for site editors to not input invalid options. ie: below is our first Umbraco site were getting ready to officially release this week or next week (1 site down, about 40 more sites to go)...

http://4allnc.ncbar.org

if you go to the initial staff contacts page located under the NC Bar Association dropdown, or visit:

http://4allnc.ncbar.org/nc-bar-association/staff-contacts.aspx

all of our contact options are dynamically generated based on the following paramaters:

-department
-department header
-department info

department is the actual parameter that is passed to our DAL and returns the correct set of data... this is the option that I would like to be rendered as a dropdown pre-populated with the param values defined in either the macro or bound via some other backend mechanism...

again, many thanks for the help and feedback...


mortenbock
Posted: Tuesday, January 08, 2008 10:05:26 PM

Rank: Addict

Joined: 7/19/2006
Posts: 733
Location: Århus, Denmark
Well, one quick fix could be to create 14 (its a lot, I know) "bool" buttons, one for each department, and then use a switch in your usercontrol to find out which department is marked "true".

Another way to go is what it seems like you have already thought about: Making a document type specifically for this macro. Here is how I would do that:

In your content tree, create a folder called "Contact Lists".
Under that folder you then create x number of documents of the type "list".

The "list" documenttype will contain your three fields, and will only be used for storing these options.

What you then do is create a macro that takes _one_ parameter: a contentpicker.

In your usercontrol you then take the nodeId, and look up the setting from that node, and then you display your list based on those parameters.

The downside is that there is a bit more work for the editor the first time they need to create a list. On the other hand, the settings can be reused on another page, since they only have to enter the department header and department info once.

Which one of the above options best could fit your needs is up to you, but I think both of them are quite a bit faster to develop, than to create a new macro parameter type.

I'm looking for a new job

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

jHodgkinson
Posted: Wednesday, January 09, 2008 4:22:23 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
thanks for the feedback Morton! I'll give those some thought...
hartvig
Posted: Wednesday, January 09, 2008 4:39:32 PM

Rank: Addict

Joined: 3/17/2008
Posts: 808
Location: Nyborg, Denmark
Quote:

Unfortunately the datatypes and the macro parameter types are not the same, and as far as I have been told, it is not a easy task to create a new macro parameter type, as you would need to modify the source for that purpose.


This is not correct, you don't need to modify the source to add new macro parameter types (I helped a pro customer with this last week, so I know for sure :-D)

Jeeeez, did I really start this :-)
mortenbock
Posted: Wednesday, January 09, 2008 4:43:54 PM

Rank: Addict

Joined: 7/19/2006
Posts: 733
Location: Århus, Denmark
Niels Hartvig wrote:

This is not correct, you don't need to modify the source to add new macro parameter types (I helped a pro customer with this last week, so I know for sure :-D)


I stand corrected :-)

Any chance for an Umbraco Book on this subject?

I'm looking for a new job

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

jHodgkinson
Posted: Thursday, January 10, 2008 5:40:51 AM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
I figured out how to do it - just had to look through the source. you just have to have your subclassed web control inherit the umbraco macroRenderings interface (look at the umbraco.macroRenderings project classes for great examples and more population specifics), compile your project, place your dll in the umbraco bin and then add the item to the macroProperties table... doesn't take long at all... amazingly cool stuff Niels - you rock!
jHodgkinson
Posted: Thursday, January 10, 2008 4:12:45 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
here's the basics for what I did on my initial test projects (not sure how textbox this method is compared to Niels' - this may be the street-wise variation ;) - I'm guessing a package would be the route to go for installation so that manual db step is not needed:

-subclass dropdownlist (or whatever .NET control type - or roll your own) and inherit IMacroGuiRendering interface and integrated with existing DAL business class. add either static or dynamic bindings in init method. compile and copy .dll to umbraco bin...







-add macro class info to umbraco "cmsMacroPropertyType" table:



-add new object type to your macro:



-add/embed macro in page or template and set macro property values:





-save and publish page and voila:



jHodgkinson
Posted: Thursday, January 10, 2008 4:18:41 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
forgot to also mention in step one you'll also need to add/customize class members/properties. in my test project subclassing the dropdownlist control I just modified the init method while retaining the value property settings since I didn't need to add any additional parameters... I used the tabPicker object as a template. consult the source umbraco.macroRenderings projects for lots of good samples...
imayat12
Posted: Thursday, January 10, 2008 10:44:05 PM

Rank: Addict

Joined: 7/19/2006
Posts: 580
Location: Preston, UK
John,

WOW :dribble:, you live and learn. This really opens up a whole new world of possibilities. If Niels is listening some potential material here for umbraco level3 course :D

Many thanks for this wonderful nugget.

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
mortenbock
Posted: Thursday, January 10, 2008 10:55:37 PM

Rank: Addict

Joined: 7/19/2006
Posts: 733
Location: Århus, Denmark
Just thinking out loud here... maybe it is possible to make a macro property type, that functions as a proxy for a regular datatype? That way if you have a datatype with prevalues that is used in a document type, then it could be reused in a macro. :hmm: how to do...

I'm looking for a new job

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

mortenbock
Posted: Thursday, January 10, 2008 10:56:29 PM

Rank: Addict

Joined: 7/19/2006
Posts: 733
Location: Århus, Denmark
Ismail Mayat wrote:

John,

WOW :dribble:, you live and learn. This really opens up a whole new world of possibilities. If Niels is listening some potential material here for umbraco level3 course :D

Many thanks for this wonderful nugget.

Regards

Ismail


Oh, and by the way, I agree 100% with Ismail :-)

Nice work!

I'm looking for a new job

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

hartvig
Posted: Friday, January 11, 2008 8:54:43 AM

Rank: Addict

Joined: 3/17/2008
Posts: 808
Location: Nyborg, Denmark
Excellent John - any chance you could turn your post into a book?

btw: This topic has been covered on the past two level 2 courses. The format of the level 2 course has changed a bit leaving more time for neat tricks on the last half of day two :)

/n

Jeeeez, did I really start this :-)
jHodgkinson
Posted: Friday, January 11, 2008 2:01:35 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
Morton - that would be way cool - a "data type picker" per say.

Niels - sure, I'd be more than happy to as long as you feel this is an accurate depiction of how to extend macro types. Is there documentation on adding a book?
HFloyd
Posted: Thursday, February 07, 2008 6:30:37 PM

Rank: Fanatic

Joined: 7/19/2006
Posts: 205
Location: New York, NY, USA
imayat12
Posted: Thursday, February 14, 2008 5:01:56 PM

Rank: Addict

Joined: 7/19/2006
Posts: 580
Location: Preston, UK
John,

I have just implemented this for an ImageGen macro. Basically one of the properties i wanted to pass in was font type so as per your example i created dropdown list populated with the options and it works nicely.

Many thanks once again for this I intend to have even more fun :thumbup:

Regards

Ismail

Level 2 certified. If it aint broke dont fix.
jHodgkinson
Posted: Friday, February 15, 2008 2:41:55 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 354
Location: Cary, NC USA
Heather - thanks so much. that's exactly what I need. now I just need to find some time to write it up. I also had a decent post on integrating spell checking into tinyMCE a while back too - that might make a helpful book as well.

Ismail - cool - sounds great. I agree, I think having the ability to populate macro data types really opens up so many doors. Normalizing option data is a big plus and can make things so much easier for the CMS users as well.
imayat12
Posted: Friday, February 15, 2008 5:22:10 PM

Rank: Addict

Joined: 7/19/2006
Posts: 580
Location: Preston, UK
John,

Dont know if your interested but Morten asked me yesterday about maybe creating some kind of project in code plex to come up with a generic extendable renderer.

I have taken your code and come up with inhertiance / interface based implemenation. Basically for any new data providers say from db / xml / csv / umbraco you create 2 new 2 classes one inherits from base class which has all the combo init stuff and umbraco macro rendering interface implementation. The second class needs to implement getdata method which sends back dictonary item of the data you want in the drop down list. For db / xml / csv / umbraco I have created blank stubs need to fill them in ;).


If your interested let me know ill get something up on codeplex. You have a quick look at my hackings here

Regards


Ismail

Level 2 certified. If it aint broke dont fix.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.