ManagerRootService class contains methods to get the data about EXM Manager Root.
You need to inject the Sitecore.Modules.EmailCampaign.Services.ManagerRootService into your class.
Looks like you need to use next method:
public ManagerRoot GetManagerRootFromChildItem(Item childItem)
{
return this.GetManagerRootFromItem(ItemUtilExt.GetParentItemFromTemplate(childItem, "{CF9C8A2A-2794-4FEA-980A-EF8426F3D6C3}")) ?? this.GetManagerRootFromItem(childItem);
}
Bellow is the Sitecore.Modules.EmailCampaign.Services.ManagerRootService methods:
public class ManagerRootService : IManagerRootService
{
private readonly ItemUtilExt _itemUtil;
private readonly EcmSettings _exmSettings;
public ManagerRootService(ItemUtilExt itemUtil, EcmSettings exmSettings)
{
Condition.Requires<ItemUtilExt>(itemUtil, nameof (itemUtil)).IsNotNull<ItemUtilExt>();
this._itemUtil = itemUtil;
this._exmSettings = exmSettings;
}
public List<ManagerRoot> GetManagerRoots()
{
string[] strArray;
using (new SecurityDisabler())
{
Item obj = this._itemUtil.GetItem("{684CAA9A-FBD3-4FFB-891E-042E56B4E09C}");
if (obj == null)
throw new EmailCampaignException("The '{0}' item is not found.", new object[1]
{
(object) "{684CAA9A-FBD3-4FFB-891E-042E56B4E09C}"
});
strArray = obj["{9E4027B2-0360-4B48-B665-FC51E55FC766}"].Split(new char[1]
{
'|'
}, StringSplitOptions.RemoveEmptyEntries);
}
return ((IEnumerable<string>) strArray).Select<string, ManagerRoot>((Func<string, ManagerRoot>) (x => this.GetManagerRootFromId(Guid.Parse(x)))).Where<ManagerRoot>((Func<ManagerRoot, bool>) (root => root != null)).OrderBy<ManagerRoot, string>((Func<ManagerRoot, string>) (x => x.InnerItem.DisplayName)).ToList<ManagerRoot>();
}
public ManagerRoot GetManagerRootFromId(Guid rootId)
{
return this.GetManagerRootFromItem(this._itemUtil.GetItem(rootId));
}
public ManagerRoot GetManagerRootFromItem(Item item)
{
return this.GetCorrectManagerRootObject(item);
}
public ManagerRoot GetManagerRootFromChildItem(Item childItem)
{
return this.GetManagerRootFromItem(ItemUtilExt.GetParentItemFromTemplate(childItem, "{CF9C8A2A-2794-4FEA-980A-EF8426F3D6C3}")) ?? this.GetManagerRootFromItem(childItem);
}
public virtual ManagerRoot GetManagerRoot(Guid managerRootId)
{
return this.GetManagerRootFromItem(new ItemUtilExt().GetItem(new ID(managerRootId)));
}
public Guid CreateRoot()
{
using (new SecurityDisabler())
{
Item obj = this._itemUtil.AddItemFromBranch(new KeyValuePair<string, string>("Email", "Email"), "{F8FAE92A-4F10-470C-AD5C-7ED9E6B636AF}", this._itemUtil.GetItem(this._exmSettings.GetDefaultRootPosition) ?? this._itemUtil.GetItem(ItemIDs.ContentRoot.ToString()));
if (obj == null)
return Guid.Empty;
return obj.ID.ToGuid();
}
}
private ManagerRoot GetCorrectManagerRootObject(Item rootItem)
{
return ManagerRoot.FromItem(rootItem);
}
}