Multiple Categories Selector removing categories added in custom handler.. bug ?

Dave Forster asked on April 14, 2016 12:45

Hi,

I've noticed some unwanted behaviour when using the Multiple Categories Selector form control on one of my pages.

When I save (or intially create) the content page I have a custom event handler (on InsertAfter) that assigns some default categories (using DocumentCategoryInfoProvider.AddDocumentToCategory) based on another setting on the page (effectively copying the categories from another document). This part works fine.

However, after my handler has done this the Multiple Category Selector runs some code that effectively undo's this.. deleting my changes! The code in question is :

~\CMSModules\Categories\Controls\MultipleCategoriesSelector.ascx.cs

        // Remove old items
        string newValues = ValidationHelper.GetString(selectCategory.Value, null);
        string items = DataHelper.GetNewItemsInList(newValues, mCurrentValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            // Add all new items to user
            foreach (string item in newItems)
            {
                int categoryId = ValidationHelper.GetInteger(item, 0);
                DocumentCategoryInfoProvider.RemoveDocumentFromCategory(Node.DocumentID, categoryId);
            }

            logUpdateTask = true;
        }

If i hide/remove the form control from my page type then everything works fine. Is this behaviour expected ? Is it a bug ? Is there a work around where I can still have the form control on the page ?

I understand that I can still manage/view the categories in the Category Property Page but having the form control provides a level of convenience.

V 9.0.12

Recent Answers


Brenden Kehren answered on April 14, 2016 14:05

Without browsing the full set of code, I'm guessing it's removing those you just added because they weren't selected in the control when it loaded or reloaded. So what it seems like is your event handler is kicking off too late and is being overwritten by the form control selections.

0 votesVote for this answer Mark as a Correct answer

Dave Forster answered on April 14, 2016 14:28

I would suggest that's more a problem with the form control as opposed to my event handler though?

My event handler is firing DocumentEvents.Update.After and DocumentEvents.Insert.After so I would have expected the record to have already been updated.. I'm not sure the form control should be doing anymore processing after that point.. correct? How can you trust the event model if thats happening ?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.