Search code examples
asp.netcommandfieldsitecorefieldtype

Sitecore: call methode from context menu item


I have created my own fieldtype ( extension of TreelistEx ). For this extension i added a second context menu item ( by default TreelistEx already has a "edit" menu item ).

I started off with linking this menu item with a command. This works fine but it doesn't realy answer to my requirements. I would need the menu item to execute a method located in the fieldtype.

TreelistEx works like this with the "edit" menu item. There is no reference to a command ( i checked Commands.config and plenty of other config files ) yet it reaches the Edit method in TreelistEx.cs

Does anyone know how i can achieve the same result ?

( Alternativly: is there a way to pass the source property of the fieldtype to a command )


Solution

  • In the core database you have define a /sitecore/system/Field types/List Types/YOURTreelistEx

    provide a control and set in the web.config below <controlSources> or provide a class and Assembly, i guess you have done this? you need to make your own control, or class

    And you have in the core db create the item /sitecore/system/Field types/List Types/YOURTreelistEx/Menu/YOURButton

    In the Message field set yourfield:yourbutton

    Modify the void IMessageHandler.HandleMessage(Message message) there is also the Command call to the Edit

    public override void HandleMessage(Message message)
    {
          Assert.ArgumentNotNull((object) message, "message");
          if (!(message["id"] == this.ID))
            return;
          switch (message.Name)
          {
            case "treelist:edit":
              Context.ClientPage.Start((object) this, "Edit");
              break;
             case "yourfield:yourbutton":
            //Call Your code;
              break;
          }
    }
    

    See for Example Creating a custom Sitecore Field