YodasMyDad / Dialogue

Forum package for Umbraco v7.1 onwards
54 stars 31 forks source link

When running Dialogue as a seperate node in the root from the reset of the site, it doesnt run (with fix) #100

Open JohnBergman opened 7 years ago

JohnBergman commented 7 years ago

When you have this situation, some of the queries don't locate the from node. Here is the fix for that in case anyone else runs into this:

Inside ContextHelper.Cs, the EnsureCorrectCultur() method needs to build the xpath string using the constant as follows

var homeNode = helper.TypedContentAtXPath("//root//"+ AppConstants.DocTypeForumRoot).FirstOrDefault();

Inside Dialog.cs, the Settings() method at the bottom should read like this so that it also looks at all of the nodes in the root, and will choose the first one (so be careful).

public static upventurSettings Settings()
{
  if (!HttpContext.Current.Items.Contains(AppConstants.SiteSettingsKey))
  {
    var currentPage = AppHelpers.CurrentPage();
    if (currentPage != null)
    {
      var forumNode = currentPage.AncestorOrSelf(AppConstants.DocTypeForumRoot);
      if (forumNode == null)
      {
        // Only do this is if we can't find the forum normally
        forumNode = currentPage.DescendantOrSelf(AppConstants.DocTypeForumRoot);
        if(forumNode==null)
        {
          var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
          forumNode = umbracoHelper.TypedContentAtRoot().Where(x => x.IsDocumentType(AppConstants.DocTypeForumRoot)).FirstOrDefault();
        }
      }
      HttpContext.Current.Items.Add(AppConstants.SiteSettingsKey, Settings(forumNode));
    }
  }
  return HttpContext.Current.Items[AppConstants.SiteSettingsKey] as upventurSettings;
}

}

The key change is this, which examines the list of root nodes for the forum's main node.

        // Only do this is if we can't find the forum normally
        forumNode = currentPage.DescendantOrSelf(AppConstants.DocTypeForumRoot);
        if(forumNode==null)
        {
          var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
          forumNode = umbracoHelper.TypedContentAtRoot().Where(x => x.IsDocumentType(AppConstants.DocTypeForumRoot)).FirstOrDefault();
        }