Copied to clipboard

Flag this post as spam?

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


  • Martin Amsinck Andersen 17 posts 103 karma points
    Nov 09, 2020 @ 11:49
    Martin Amsinck Andersen
    1

    Adding Block List Editor elemtens via on contentService created IContent

    I'm trying to add new content to a nested BlockListEditor via the ContentService in an UmbracoApiController.

    I'm not sure how to accomplish this.

    I have a dataset with multiple texts and youtube video ids, i need to insert into the BlockListEditor as elements.

    1. I'm creating new Icontent via the ContentService.Create()
    2. I'm setting values via the .SetValue("alias", "somevalue"), works as expected

    Now i need to add elements to a BlockListEditor the same way. How do i create the elements and/or the json for the BlockListEditor ?

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Nov 09, 2020 @ 12:52
    Søren Gregersen
    1

    Hi Martin,

    I would suggest taking a look at what the output of the editor is, and then change what you need.

    Another way is to read the code that the editor is using, and then figure out the methods used. It may be a bit difficult to get working, since it is based on something that is not static (doc type setup).

    hth :)

  • Martin Amsinck Andersen 17 posts 103 karma points
    Nov 09, 2020 @ 13:23
    Martin Amsinck Andersen
    0

    Hi Søren

    I've been doing that :)

    The BlockListEditor is based on json, stored in [umbracoPropertyData] i the database.

    The problem for me right now, is how to create the UDI's stored on each element in the json, and what are the being used for?

    {
    "layout": {
        "Umbraco.BlockList": [
            {
                "contentUdi": "umb://element/ea006afebddf4e6d85ee3cbeca320fb4"
            }
        ]
    },
    "contentData": [
        {
            "contentTypeKey": "9f8129ee-7d8f-4e89-b951-0ffd4b844100",
            "udi": "umb://element/ea006afebddf4e6d85ee3cbeca320fb4",
            "text": "<p>some rte text</p>",
            "image": "umb://media/6b8b792c02444c00b1b048d945059b4d"
        }
    ],
    "settingsData": [] }
    
  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Nov 09, 2020 @ 13:48
    Søren Gregersen
    100

    Hi Martin,

    Based on that json you posted:

    layout -> umbraco.blocklist -> a list of blocks, that points to content

    contentData -> list of content

    The list of content has an udi, that is made from a Guid like this:

    var udi = Umbraco.Core.Udi.Create("element", Guid.NewGuid());
    

    I would guess that the other properties in the content, is mapped to properties defined by the content type, identified by the contentTypeKey.

    hth :)

  • Martin Amsinck Andersen 17 posts 103 karma points
    Nov 09, 2020 @ 13:57
    Martin Amsinck Andersen
    1

    Thx, i'm on the right track now i think :)

  • Martin Amsinck Andersen 17 posts 103 karma points
    Nov 10, 2020 @ 08:00
    Martin Amsinck Andersen
    0

    Still having a hard time figuring this out - mainly the umb://element/ UDI.

    I cant figure out what this is used for, is this just a temporary UDI, for when this get resolved New RFC: How to store Element Data, being discussed here Initial proposal for a way to store Element Data.

    Should the Udis reference something, or are the just some kind of early placeholders, until we find a way to store the element data somewhere else in the database, and not in json on the specific property in [umbracoPropertyData]

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Nov 10, 2020 @ 09:28
    Søren Gregersen
    1

    yes, it's just an internal ref :)

    It may be stored in a different way later on, but for now it looks in the contentData array (first).

  • Martin Amsinck Andersen 17 posts 103 karma points
    Nov 10, 2020 @ 09:29
    Martin Amsinck Andersen
    1

    Thx - that was my last worry :)

  • Dave Hanvey 15 posts 96 karma points
    Mar 02, 2021 @ 21:22
    Dave Hanvey
    0

    Hi, did you ever get this working?

    I have tried the same thing but get an this error:

    Error parsing Infinity value. Path '', line 1, position 2. Exception Details Newtonsoft.Json.JsonReaderException: Error parsing Infinity value. Path '', line1, position 2.

    I have also tried copying the value from umbracoPropertyData for a version where I manually created the BlockList items but that gives the same error.

    Thanks for any help you can be.

Please Sign in or register to post replies

Write your reply to:

Draft