/// <summary> /// Gets the url for a page at a specific page or custom entity version, loaded inside the /// visual editor. Note that this method does not validate permissions in any way, it simply /// formats the route correctly. /// </summary> /// <param name="route">The page to link to.</param> /// <param name="versionRoute">The version of the page or custom entity to link to.</param> public string VisualEditor( PageRoutingInfo route, IVersionRoute versionRoute ) { if (route == null) { return(string.Empty); } if (versionRoute == null) { throw new ArgumentNullException(nameof(versionRoute)); } var isEditingCustomEntity = versionRoute is CustomEntityVersionRoute; // Some of the latest version states will have a default view e.g. preview // or live so check for these first before we defer to showing by version number if (versionRoute.IsLatestPublishedVersion && route.IsPublished()) { // Published, so show live view return(VisualEditor(route, VisualEditorMode.Live, isEditingCustomEntity)); } else if (versionRoute.WorkFlowStatus == WorkFlowStatus.Draft) { // Draft version, so show draft return(VisualEditor(route, VisualEditorMode.Preview, isEditingCustomEntity)); } var baseUrl = Page(route); var queryParams = new Dictionary <string, string>(2); queryParams.Add("version", versionRoute.VersionId.ToString()); if (isEditingCustomEntity) { queryParams.Add(VISUAL_EDITOR_QS_EDITTYPE, VISUAL_EDITOR_QS_EDITTYPE_ENTITY); } else if (route.CustomEntityRoute != null) { queryParams.Add(VISUAL_EDITOR_QS_EDITTYPE, VISUAL_EDITOR_QS_EDITTYPE_PAGE); } var url = QueryHelpers.AddQueryString(baseUrl, queryParams); return(url); }
/// <summary> /// Gets the url for a page, formatted with specific visual editor /// parameters. Note that this method does not validate permissions /// in any way, it simply formats the route correctly. /// </summary> /// <param name="route">The page to link to.</param> /// <param name="visualEditorMode"> /// The mode to set the visual editor to. Note that this method cannot be /// used for VisualEditorMode.SpecificVersion and will throw an exception if /// you try. To get the url for a specific version, you need to use the overload /// accepting an IVersionRoute parameter. /// </param> /// <param name="isEditingCustomEntity"> /// For custom entity pages, this option indicates whether the editing context /// should be the custom entity rather than the (default) page. /// </param> public string VisualEditor( PageRoutingInfo route, VisualEditorMode visualEditorMode, bool isEditingCustomEntity = false ) { if (route == null) { return(string.Empty); } var baseUrl = Page(route); var queryParams = new Dictionary <string, string>(2); switch (visualEditorMode) { case VisualEditorMode.Any: var latestVersion = route.GetVersionRoute(isEditingCustomEntity, PublishStatusQuery.Latest, null); if (latestVersion.WorkFlowStatus == WorkFlowStatus.Draft || !route.IsPublished()) { queryParams.Add(VISUAL_EDITOR_QS_MODE, VISUAL_EDITOR_QS_MODE_PREVIEW); } else { queryParams.Add(VISUAL_EDITOR_QS_MODE, VISUAL_EDITOR_QS_MODE_LIVE); } break; case VisualEditorMode.Preview: queryParams.Add(VISUAL_EDITOR_QS_MODE, VISUAL_EDITOR_QS_MODE_PREVIEW); break; case VisualEditorMode.Edit: queryParams.Add(VISUAL_EDITOR_QS_MODE, VISUAL_EDITOR_QS_MODE_EDIT); break; case VisualEditorMode.Live: queryParams.Add(VISUAL_EDITOR_QS_MODE, VISUAL_EDITOR_QS_MODE_LIVE); break; case VisualEditorMode.SpecificVersion: throw new Exception($"To create a url for {nameof(VisualEditorMode)}.{nameof(VisualEditorMode.SpecificVersion)} you should use the overload that takes an {nameof(IVersionRoute)} parameter"); default: throw new Exception($"{nameof(VisualEditorMode)}.{visualEditorMode} not supported by {nameof(PageRouteLibrary)}.{nameof(VisualEditor)}()"); } if (isEditingCustomEntity) { queryParams.Add(VISUAL_EDITOR_QS_EDITTYPE, VISUAL_EDITOR_QS_EDITTYPE_ENTITY); } else if (route.CustomEntityRoute != null) { queryParams.Add(VISUAL_EDITOR_QS_EDITTYPE, VISUAL_EDITOR_QS_EDITTYPE_PAGE); } var url = QueryHelpers.AddQueryString(baseUrl, queryParams); return(url); }