Copied to clipboard

Flag this post as spam?

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


  • Pavel Gurecki 55 posts 158 karma points
    Jun 18, 2014 @ 13:24
    Pavel Gurecki
    1

    Content Picker GetPropertyValue<int> is broken (v.6.2.1) - umbracoRedirect doesn't work

    Hi guys,

    just upgraded my Umbraco 6.1.3 install to 6.2.1. Using [...] Converters package 1.0.4-beta.

    When we have ContentPicker value converter to IPublishedContent type object, other default converters doesn't seem to work, especially node.GetPropertyValue<int>("contentPickerField"). It always returns 0. It is because value converter returns IPublishedContent object, which can't be converted to requested <int> value.

    For now I've seen that this breaks two things:

     

    1. umbracoRedirect - somewhere in the core probably GetPropertyValue<int> is used, always getting 0 and thus redirects doesn't work
    2. umbracoPageNotFound - same here, this is implemented in ucomponents (or will be, taken from https://gist.github.com/leekelleher/9367600 ). Not a big issue, but it shows that there might be other places that get affected
    As a workaround, I've added some property alias checks in ContentPickerPropertyEditorValueConverter.cs:
     public bool IsConverterFor(Guid propertyEditorId, string docTypeAlias, string propertyTypeAlias)
            {
                ...
                return Guid.Parse("158aa029-24ed-4948-939e-c3da209e5fba").Equals(propertyEditorId) && _propertyTypeAlias != "umbracoRedirect" && _propertyTypeAlias != "umbracoPageNotFound";
            }

     

    I personally do not use bitbucket (waiting for github), so it would be good if somoeone could create a commit for this.

    Any ideas how it can be solved without hardcoding property aliases?

    Probably the nicest solution would be to somehow write separate methods for separate types, ex:

           public Attempt<int> ConvertPropertyValueInt(object value)
            {
                int nodeId; 
                if (value != null && int.TryParse(value.ToString(), out nodeId))
                {
                    return new Attempt<int>(true, nodeId);
                }
                else
                {
                    return Attempt<int>.False;
                }
            }

    But I don't think something like this is possible now. Maybe I should create thread on main Umbraco forum for this.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 18, 2014 @ 16:31
    Jeavon Leopold
    1

    Hi Pavel,

    That's a really good point, I already handle the same issue for "umbracoInternalRedirectId" in both the v1.1 (Umbraco6.2) and the v2(Umbraco v7) branches so I'm going to add these two additional properties to not convert.

    I just this morning began the process of moving from BitBucket to GitHub and have completed the v2 move, I'm now working on moving v1.1, so it will be there shortly.

    I'll let you know when I release the new versions, there will also be Nuget packages as alternatives to the Umbraco packages.

    Cheers,

    Jeavon

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 19, 2014 @ 18:14
    Jeavon Leopold
    0

    Hi Pavel,

    I have been looking into this and unfortunately I've not been able to do this with Umbraco v6 but thankfully it is possible with v7 due the changes in the way the value converters work.

    I think for a v6 site you may find that using a textfield editor for these special properties is a viable workaround, if not you could either do a custom build of the converters without the content converter or create a duplicate of the content picker property editor in your solution just for these properties.

    You can find the source code for v1 (Umbraco v6) now on GitHub here

    Thanks,

    Jeavon

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 19, 2014 @ 18:29
    Jeavon Leopold
    0

    Doh, maybe I'm wrong, just after I posted that it now seems to be work.....

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 19, 2014 @ 19:03
    Jeavon Leopold
    0

    I've just released v1.1.0 which does not convert umbracoRedirect or umbracoInternalRedirectId but you will need to adjusts Lee's code for umbracoPageNotFound as this is not a Umbraco standard.

    Could you please let me know if it works?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 19, 2014 @ 19:05
    Jeavon Leopold
    0

    e.g.

            var pageNotFoundId = node.GetPropertyValue<IPublishedContent>("umbracoPageNotFound");
            if (pageNotFoundId == null)
                return false;
    
  • Pavel Gurecki 55 posts 158 karma points
    Jun 23, 2014 @ 09:03
    Pavel Gurecki
    0

    Hi Jeavon,

    thanks for quick reply.

    Good to hear that this will work in v7.

    As for v6 I will edit Lee's code to use IPublishedContent instead of int, it will work (tried that already).

    Cheers

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 23, 2014 @ 09:14
    Jeavon Leopold
    100

    v1.1.0 should work and is for v6.2

  • Pavel Gurecki 55 posts 158 karma points
    Jun 23, 2014 @ 14:06
    Pavel Gurecki
    0

    I can confirm that umbracoRedirect works on v6.2.1 with package v1.1.0 .

    But for other properties ("umbracoPageNotFound", etc.), GetPropertyValue<int> will always return 0. IPublishedContent return type should be used instead.

Please Sign in or register to post replies

Write your reply to:

Draft