Copied to clipboard

Flag this post as spam?

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


  • Johannes Lantz 156 posts 838 karma points c-trib
    Apr 15, 2019 @ 07:14
    Johannes Lantz
    0

    Deleted picked items in pickers

    Hi all!

    I just have to start by saying that I absolutly love Umbraco!

    But this is the biggest issue that experience.

    Let's say I have a content picker. I pick a node and then delete the picked node. I would get a "null" error even if I have this if statement.

    @if(Model.Content.HasValue("contentPicker"))
    {
        var test = Model.Content.GetPropertyValue<IPublishedContent>("contentPicker");
    
        @test.Name
    }
    

    The node is still picked but this shows in the backoffice enter image description here

    If you empty the recycle bin the node disapears from the picker but the "null" error is still ongoing. It's not until you "save and publish" the node again with nothing picked that the error stop occurring.

    This is something that I experience quite often during development.

    What I would like, is that the *node disappears from the pickereven if it's in the recycle bin and that the "null" error dissapears . * Is a nyone else experiencing this? Or dose anyone have an solution to this? or know how I could go about doing this myself?

    (This is testen on Umbraco 7.14 with the default kit installed)

    Thanks!

    //Johannes

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 15, 2019 @ 07:59
    Dave Woestenborghs
    0

    Hi Johannes,

    I always write defensive code to prevent errors during rendering when something is unpublished or deleted.

    Another option is to install my Nexu package. This will keep track of internal links and will warn editors when they try to delete/unpublish a item that is in use in another content item.

    https://our.umbraco.com/packages/backoffice-extensions/nexu/

    Dave

  • Johannes Lantz 156 posts 838 karma points c-trib
    Apr 15, 2019 @ 14:18
    Johannes Lantz
    0

    Hi Dave!

    I am a bit unsure on the term "defensive code". Do you mean that I could rewrite the if statement to not "break" even if the selected node is in the recycle bin? if so, how would that look?

    I took a look at the plugin and it's really good! although it would be great if you were forced to unpick the node before you could delete it. And that you could unpick it from the "are you sure" modal. Is the project on github? would love to take a look at it myself!

    //Johannes

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 15, 2019 @ 14:35
    Dave Woestenborghs
    0

    Hi Johannes,

    Normally the propertyvalue converter for the content picker should hanlde this.

    So if you do

    Model.Content.GetPropertyValue<IPublishedContent>("contentPicker");
    

    It should only return published items

    https://github.com/umbraco/Umbraco-CMS/blob/v7/dev/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerPropertyConverter.cs

    What type are using for the content picker ? I assume it is the built in content picker.

    Dave

  • Johannes Lantz 156 posts 838 karma points c-trib
    Apr 15, 2019 @ 16:36
    Johannes Lantz
    100

    I thought that HasValue("contentPicker") was the best way to go but after some tinkering I came up with this:

        var foo = Model.Content.GetPropertyValue<IPublishedContent>("contentPicker");
        if(foo != null)
        {
           @foo.Name
        }
    

    So time start using this instead of HasValue("contentPicker") ..

    Thanks for everything Dave! And if I may say, your plugin should be built in with Umbraco!

    // Johannes

Please Sign in or register to post replies

Write your reply to:

Draft