Follow target for a treelist field in Sitecore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FollowTreelist : Command | |
{ | |
public override void Execute(CommandContext context) | |
{ | |
ID id = ID.Null; | |
bool isId = false; | |
var fieldId = context.Parameters["fieldId"]; | |
if (!string.IsNullOrEmpty(fieldId)) | |
{ | |
var form = System.Web.HttpContext.Current.Request.Form; | |
if (form != null) | |
{ | |
string rawValue = form[string.Format("{0}{1}", fieldId, Constants.Selected)]; | |
if (string.IsNullOrEmpty(rawValue)) | |
{ | |
rawValue = form[string.Format("{0}{1}", fieldId, Constants.AllSelected)]; | |
} | |
string targetId = rawValue.Substring(rawValue.LastIndexOf("|", StringComparison.InvariantCultureIgnoreCase) + 1); | |
isId = ID.TryParse(targetId, out id); | |
// BUG fix - ID.TryParse fails unformatted ID string passed by FIELDID_all_selected | |
if (!isId) | |
{ | |
try | |
{ | |
id = new ID(targetId); | |
isId = true; | |
} | |
catch (Exception e) | |
{ | |
isId = false; | |
} | |
} | |
} | |
} | |
Sitecore.Context.ClientPage.SendMessage(this, "item:load(id=" + (isId ? id.ToString() : string.Empty) + ")"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment