Copied to clipboard

Flag this post as spam?

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


  • John P Scott 14 posts 71 karma points
    Apr 03, 2019 @ 14:08
    John P Scott
    0

    SetTagsValue does not allow you to set a Tag Group

    Hi,

    I am rewriting an Umbraco 7 site in Umbraco 8. The method for setting tags in v7 (IContentBase.SetTags) has an optional parameter for setting the tag group.

    The equivalent method for v8 (SetTagsValue) does not have this facility. Looking at the source for v8 it appears to be missing - there is an internal static method which is passed the TagConfiguration though the Group name is ignored in the implementation.

    I need to set the Group for tags on images to the id of the Folder in which they reside as part of the image import process. This is acheived in v7 using:

    img.SetTags("myTagField", myArrayOfTags, true, parentFolderId.ToString());

    Is there any way to get round this?

    Any help will be gratefully receieved.

    Scotty

  • John P Scott 14 posts 71 karma points
    Apr 03, 2019 @ 16:23
    John P Scott
    0

    Update

    On inspection it seems that a Tag property added as an extension of the Image media type (and probably other types) must have the Tag group name set and it can't be overridden on an image by image basis.

    I have resorted to building the list of tags for images in a folder the hard way (note: I'm using a strongly typed Model with ModelsBuilder):

    SortedDictionary<string, int> tags = new SortedDictionary<string, int>();
    foreach (GalleryImageMedia img in folder.Children)
    {
        foreach (string tag in img.Tags)
        {
            if (tags.ContainsKey(tag))
            {
                tags[tag] = tags[tag] + 1;
            }
            else
            {
                tags.Add(tag, 1);
            }
        }
    };
    
Please Sign in or register to post replies

Write your reply to:

Draft