Linking to the Model in Sitecore change request and Mapping Multilist/Treelist fields issue/change

341 views
Skip to first unread message

Mike Sprague

unread,
May 15, 2013, 5:45:10 PM5/15/13
to glass...@googlegroups.com
1. Linking to the Model in Sitecore

It would be good to handle going from the Model property on the various renderings types to the Model content item which has the Model Type field.  In the examples the type is in the Model field which is a link field.  I did something like this to override the getModel pipeline:

            Item obj = ObjectExtensions.ValueOrDefault<RenderingItem, Item>(rendering.RenderingItem, (Func<RenderingItem, Item>)(i => i.InnerItem));
            if (obj == null)
                return (object) null;
            else
            {
                var modelItem = obj["Model"];
                var model = ObjectExtensions.ValueOrDefault<Item, string>(
                        MvcSettings.GetRegisteredObject<ItemLocator>().GetItem(modelItem),
                        (Func<Item, string>)(i => i["Model Type"]));

2. Glass v2 mapped Multilist fields to IEnumerable<Guid>, while v3 attempts to map to IEnumerable<model>.  We're using TDS to generate the model code at which time we can't figure out what the <model> should be for the Multilist field.  Can a configuration property to drive which way it tries to map be implemented?  Or if there is a way to figure out that model, can an example be provided?

Thanks,
Mike

Michael Edwards

unread,
May 17, 2013, 2:24:07 AM5/17/13
to Mike Sprague, glass...@googlegroups.com
Mike

1, Could you explain the use case for this? I am not sure what/why you want to do this.


2, Both v2 and V3 were able to map guid based fields to Models, e.g. drop links, tree lists, multi lists. They can also both map to IEnumerable<Guid>. I am not sure if there is a way to do this but I notice the there is a Custom Data field in TDS, could you add the name of the target model to this field?

Cheers

Mike


--
You received this message because you are subscribed to the Google Groups "Glass.Mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glassmapper...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mike Sprague

unread,
May 17, 2013, 3:05:21 PM5/17/13
to glass...@googlegroups.com, Mike Sprague, mikeed...@googlemail.com
1. Basically because it fits how Sitecore is implemented.  If you look at the Content tab of a View Rendering, the Model field is type Internal Link with a Source = /sitecore/layout/models, so Sitecore is expecting that field to point to the Model Content Item that specifies the type.  Your implementation assumes that the Model type is in the Model field.  If you do that, you'll get a validation error in Sitecore since it doesn't map to a Model Content Item.

2.  That's a good idea, I will have to try the Custom Data.  I'm curious if when the items in the TDS project are synced, if it would overwrite that.

Thanks,
Mike
Reply all
Reply to author
Forward
0 new messages