Copied to clipboard

Flag this post as spam?

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


  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Apr 02, 2014 @ 13:00
    Jeavon Leopold
    0

    v6/7 API equivalent for uQuery.GetUmbracoObjectType

    Hi All,

    I have been working on a value converter for the v7 multinode tree picker, this value converter doesn't know if the picker is set to pick "content" or "media" but it needs to know.

    I have previously used (and can still use) a really useful uQuery method called GetUmbracoObjectType which makes this really simple but I'm wondering if there is a current API method that does the same or if not should there be one?

    if (uQuery.GetUmbracoObjectType(1234) == uQuery.UmbracoObjectType.Document)
    

    An alternative approach is to look at the prevalue setting itself, but this is a lot more complicated, here's how it looks:

            var dts = ApplicationContext.Current.Services.DataTypeService;
            var startNodePreValue =
                dts.GetPreValuesCollectionByDataTypeId(propertyType.DataTypeId)
                    .PreValuesAsDictionary.FirstOrDefault(x => x.Key.ToLowerInvariant() == "startNode".ToLowerInvariant()).Value.Value;
    
            var startNodeObj = JsonConvert.DeserializeObject<JObject>(startNodePreValue);
            var pickerType = startNodeObj.GetValue("type").Value<string>();
    

    Thanks in advance!

    Jeavon

  • Morten Christensen 596 posts 2769 karma points admin hq c-trib
    Apr 02, 2014 @ 13:14
    Morten Christensen
    4

    Yes, ApplicationContext.Current.Services.EntityService.GetObjectType(into id)

    This will return an UmbracoObjectTypes enum, which I believe is what you are looking for.

    - Morten

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Apr 02, 2014 @ 13:30
    Jeavon Leopold
    0

    Hey Morten,

    Looks totally perfect, however I'm getting an exception when passing in a node id?

    var objectType = ApplicationContext.Current.Services.EntityService.GetObjectType(1068);
    

    Exception:

    System.InvalidCastException was unhandled by user code
      HResult=-2147467262
      Message=Object must implement IConvertible.
      Source=mscorlib
      StackTrace:
           at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
           at System.Convert.ChangeType(Object value, Type conversionType)
           at Umbraco.Core.Persistence.Database.ExecuteScalar[T](String sql, Object[] args)
           at Umbraco.Core.Persistence.Database.ExecuteScalar[T](Sql sql)
           at Umbraco.Core.Services.EntityService.GetObjectType(Int32 id)
           at OurUmbraco.PropertyConverters.MultiNodeTreePickerPropertyConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview) in c:\Users\Jeavon\Documents\Visual Studio Projects\BitBucket Umbraco-Core-Property-Editor-Converters\OurUmbraco.PropertyConverters\MultiNodeTreePickerPropertyConverter.cs:line 48
           at Umbraco.Core.Models.PublishedContent.PublishedPropertyType.ConvertDataToSource(Object source, Boolean preview)
           at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0()
           at System.Lazy`1.CreateValue()
      InnerException: 
    

    Thanks

    Jeavon

  • Morten Christensen 596 posts 2769 karma points admin hq c-trib
    Apr 02, 2014 @ 13:34
    Morten Christensen
    0

    Oops, that doesn't look good. What type of item are you fetching the UmbracoObjectType for?

     

    - Morten

  • Morten Christensen 596 posts 2769 karma points admin hq c-trib
    Apr 02, 2014 @ 13:40
    Morten Christensen
    0

    Ah, its doing an ExecuteScalar<string> on nodeObjectType which is actually a nullable Guid. So that's probably where the conversion issue is happening :-S

    Should be easy to fix though.

     

    - Morten

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Apr 02, 2014 @ 13:40
    Jeavon Leopold
    0

    It's just a ContentItem, jut tried with a Media item and same exception

    Jeavon

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Apr 02, 2014 @ 13:42
    Jeavon Leopold
    0

    Ah ha, like easy enough fix to make it into v7.1 RTM?

  • Edwin van Koppen 156 posts 270 karma points
    Jul 03, 2014 @ 22:43
    Edwin van Koppen
    0

    I dit it like this (not so clean):

     PreValue preValueType = (preValues.Where(m => m.Key == "startNode")).First().Value;
     if(preValueType.Value.IndexOf("content") > -1) {
        classString.AppendLine("\t\t[UmbracoContent]");
     } if(preValueType.Value.IndexOf("media") > -1) {
        classString.AppendLine("\t\t[UmbracoMedia]");
    }
    

    I've got a other problem that maybe someone here know. If building a object generator and i need to find out if an object is a string or an other object. I've got the DataType like this:

    IDataTypeDefinition dataType = umbracoContext.Application.Services.DataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(propertyType.PropertyEditorAlias).First();
    

    But i can't find what type of object that is. I've seen that the umbracoWidth is the Type int but where can i find that in the DataTypeDefinition?

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Jul 04, 2014 @ 08:25
    Jeavon Leopold
    100

    The bug with GetObjectType has been fixed in the upcoming v7.1.5

  • Edwin van Koppen 156 posts 270 karma points
    Jul 04, 2014 @ 09:30
    Edwin van Koppen
    0

    DataTypeService don't have a GetObjectType.. or must i use the EntityService to get the datatype object type?

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Jul 04, 2014 @ 09:58
    Jeavon Leopold
    0

    Yes, you need to use EntityService to get the Umbraco object type.

    What is it you are creating?

  • Edwin van Koppen 156 posts 270 karma points
    Jul 04, 2014 @ 10:09
    Edwin van Koppen
    0

    I've building some kind of Entity Framework for Umbraco. I already have the mapping and save in the open source project

    http://our.umbraco.org/projects/developer-tools/w3s-umbraco-object-relation-mapper

    see how it works https://github.com/W3S-uORM/uORM

    and it would be nice if you have a render class that create the objects automatically.

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Jul 04, 2014 @ 10:12
    Jeavon Leopold
    1

    Ah ok, do you know about IPublishedContentModelFactory?

    Watch Stephan's session from CodeGarden at around 45 minutes http://stream.umbraco.org/video/9921022/core-internals-for-website-development

  • Edwin van Koppen 156 posts 270 karma points
    Jul 04, 2014 @ 10:19
    Edwin van Koppen
    0

    whoo double..

  • Edwin van Koppen 156 posts 270 karma points
    Jul 04, 2014 @ 10:43
    Edwin van Koppen
    0

    Did not know that Jeavon! Thanks, But because i got my own ORM (with save and dependency injection) i need to write my own that works with that ORM. But i can look at his code how he finds the type. Thanks!

  • Edwin van Koppen 156 posts 270 karma points
    Jul 07, 2014 @ 11:14
    Edwin van Koppen
    0

    Jeavon, maybe you know this. I'm trying to find the ClrType from a object. This is what is got:

    Type type = Umbraco.Core.Models.PublishedContent.PublishedContentType.Get(publishedItemType, contentType.Alias).GetPropertyType(propertyType.Alias).ClrType;
    

    But if i look at the mediatype image, umbracowidth it says it's a object. But in a debugger it says it is a Int? Where can i find that ClrType that is that Int?

  • Jeavon Leopold 3008 posts 13210 karma points MVP 7x admin c-trib
    Jul 07, 2014 @ 22:20
    Jeavon Leopold
    0

    I'm afraid I don't but IPublishedContentModelFactory is not part of Stephan's model generator, it is a hook built into the Umbraco v7.1.4 Core for creating projects such as this. I believe it may expose the types of all the properties in the installation (taking into account value converters) as I think I remember Stephan talking about it.

  • Edwin van Koppen 156 posts 270 karma points
    Jul 08, 2014 @ 09:19
    Edwin van Koppen
    0

    I've already talked with Stephan about it and he came up with example above. I just seen this tool https://github.com/lars-erik/Umbraco.CodeGen and it uses this to to the mapping:

    <TypeMappings Default="String" DefaultDefinitionId="0cc0eba1-9960-42c9-bf9b-60e150b429ae">
    <TypeMapping DataTypeId="Umbraco.TrueFalse" Type="Boolean" Description="True/false"/>
    <TypeMapping DataTypeId="Umbraco.Integer" Type="Int32" Description="Numeric"/>
    <TypeMapping DataTypeId="Umbraco.UploadField" Type="Int32" Description="Upload"/>
    <TypeMapping DataTypeId="Umbraco.DateTime" Type="DateTime" Description="Date Picker with time"/>
    <TypeMapping DataTypeId="Umbraco.ColorPickerAlias" Type="String" Description="Approved Color"/><!-- System.Drawing.Color <- I Wish.. -->
    <TypeMapping DataTypeId="Umbraco.FolderBrowser" Type="Object" Description="Folder Browser"/>
    <TypeMapping DataTypeId="Umbraco.Date" Type="DateTime" Description="Date Picker"/>
    <TypeMapping DataTypeId="Umbraco.ContentPickerAlias" Type="Int32" Description="Content Picker"/>
    <TypeMapping DataTypeId="Umbraco.MediaPicker" Type="Int32" Description="Media Picker"/>
    <TypeMapping DataTypeId="Umbraco.TinyMCEv3" Type="System.Web.IHtmlString" Description="Richtext editor"/>
    

    So i don't think it's possible?

Please Sign in or register to post replies

Write your reply to:

Draft