Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public class CreateSite : Command
  2. {
  3. //protected void CreateSite()
  4. //{
  5. // //Change the eventName here
  6. // SheerResponse.Timer("multisite:createSiteA", 100);
  7. //}
  8.  
  9. public static string InvalidPath = "/sitecore/templates/Branches/Project/Common/Sites/Site Root";
  10.  
  11.  
  12. public override void Execute(CommandContext context)
  13. {
  14. if (context.Items.Length == 1)
  15. {
  16. var item = context.Items[0];
  17. var parameters = new NameValueCollection();
  18. parameters["id"] = item.ID.ToString();
  19. parameters["language"] = item.Language.ToString();
  20. parameters["database"] = item.Database.Name;
  21. Sitecore.Context.ClientPage.Start(this, "Run", parameters);
  22. }
  23. }
  24.  
  25. protected void Run(Sitecore.Web.UI.Sheer.ClientPipelineArgs args)
  26. {
  27. if (!args.IsPostBack)
  28. {
  29. //Means we are in the initial step, we want to ask for the name of the news
  30. Sitecore.Context.ClientPage.ClientResponse.Input("Enter site name:",
  31. Sitecore.Globalization.Translate.Text("Site Name"),
  32. Sitecore.Configuration.Settings.ItemNameValidation, "'$Input' is not a valid name.", 100);
  33. args.WaitForPostBack();
  34. }
  35. else
  36. {
  37. //Now we got a postback, which means we got a response
  38. if (!String.IsNullOrEmpty(args.Result) && args.Result != "undefined")
  39. {
  40. var db = Sitecore.Configuration.Factory.GetDatabase(args.Parameters["database"]);
  41. var parent = db.GetItem(args.Parameters["id"], Language.Parse(args.Parameters["language"]));
  42.  
  43. BranchItem branch = parent.Database.GetItem(Constants.BranchSite.SiteA);
  44. var item = parent.Add(args.Result, branch);
  45.  
  46. // DO YOUR WORK HERE
  47.  
  48. Sitecore.Context.ClientPage.SendMessage(this, "item:load(id=" + item.ID + ")");
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement