5

I have a requirement in which I need to check:

if keyword is created with copy-paste then I need to remove the related keywords from the destination (new) keyword and if keyword is moved using cut-paste then I need to keep the related keyword.

Can you please suggest how can I achieve this using Event system?

  • 1
    No event will happen server side for a copy-paste or cut-paste. Your only chance will be to implement something client side, such as a GUI Extension. – Chris Morgan Feb 2 '15 at 20:27
  • There will certainly be an event for the actual paste -- which is clearly the right moment to actually apply a change. It doesn't matter if the user selects Cut or Copy and then never selects Paste. – Peter Kjaer Feb 3 '15 at 6:54
7

You should be able to do this by subscribing to initiated phase of the copy event of a Keyword and removing the related Keywords.

For example:

EventSystem.Subscribe<Keyword, CopyEventArgs> (HandlerForKeywordCopyInitiated, EventPhases.Initiated);

Cutting and pasting is really just a save event with a new parent item. But since you wish to keep the related Keywords in that case anyway, you don't have to do anything for that scenario.

  • The problem with copy event is you don't get destination object so I can't do anything with copy event as per my understanding, let me know if you think otherwise. – Hiren Kaku Feb 3 '15 at 18:05
3

The general RepositoryLocalObject.Copy API (with associated CopyEventArgs) is intended to copy Repository Local Objects in general (incl. Keywords) within an Organizational Item or to another Organizational Item.

However, the Organizational Item of a Keyword is always a Category; a Taxonomy of Keywords looks like a containment tree in the GUI but is technically speaking just a tree representation of a Directed Acyclic Graph formed by Parent-Child associations between Keywords.

For example: if you have the following Taxonomy:

 Location (Category)
  USA (Keyword)
    Orlando (Keyword)

Then the Organizational Item (Keyword.OrganizationalItem) of both Keywords is the Category "Location"; the fact that Keyword "Orlando" is under "USA" in the taxonomy tree representation is because Keyword "Orlando" has Keyword "USA" as a Parent Keyword (Keyword.ParentKeywords).

Long story short: the general Copy API can copy a Keyword to another Category, but not to another location in a taxonomy of Keywords. However, there is another API for that purpose: Keyword.CopyToKeyword (with associated CopyToKeywordEventArgs).

Likewise, for moving a Keyword to another location in a Taxonomy, there is a separate Keyword.MoveToKeyword API (with associated MoveToKeywordEventArgs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.