public HttpResponseMessage GetBlockPreviewMarkup([FromBody] BlockPreview data) { var contentType = Services.ContentTypeService.Get(data.ContentTypeAlias); var publishedContentType = new Lazy <IPublishedContentType>(() => _publishedContentTypeFactory.CreateContentType(contentType)).Value; var propertyType = publishedContentType.PropertyTypes.FirstOrDefault(x => x.Alias == data.PropertyAlias); var editor = new BlockListPropertyValueConverter( _profilingLogger, new BlockEditorConverter(_publishedSnapshotAccessor, _publishedModelFactory)); var page = default(IPublishedContent); // If the page is new, then the ID will be zero if (data.PageId > 0) { // Get page container node page = Umbraco.Content(data.PageId); if (page == null) { // If unpublished, then fake PublishedContent page = new UnpublishedContent(data.PageId, Services, _publishedContentTypeFactory, Current.PropertyEditors); } } var converted = editor.ConvertIntermediateToObject(page, propertyType, PropertyCacheLevel.None, data.Value, false) as BlockListModel; var model = converted[0]; // Render view var partialName = string.Format(ConfigurationManager.AppSettings["BlockTypeGridViewPreviewPath"] ?? "~/Views/Partials/BlockList/Components/{0}.cshtml", model.Content.ContentType.Alias); var markup = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext, UmbracoContext); // Return response var response = new HttpResponseMessage { Content = new StringContent(markup ?? string.Empty) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html); return(response); }
public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int pageId) { var page = default(IPublishedContent); // If the page is new, then the ID will be zero if (pageId > 0) { // Get page container node page = UmbracoContext.ContentCache.GetById(pageId); if (page == null) { // If unpublished, then fake PublishedContent (with IContent object) page = new UnpublishedContent(pageId, Services); } } // Convert item var content = InnerContentHelper.ConvertInnerContentToPublishedContent(item, page); // Construct preview model var model = new PreviewModel { Page = page, Item = content }; // Render view var markup = ViewHelper.RenderPartial(content.DocumentTypeAlias, model); // Return response var response = new HttpResponseMessage { Content = new StringContent(markup ?? string.Empty) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html); return(response); }
public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUri] int pageId) { var page = default(IPublishedContent); // If the page is new, then the ID will be zero if (pageId > 0) { // Get page container node page = UmbracoContext.ContentCache.GetById(pageId); if (page == null) { // If unpublished, then fake PublishedContent (with IContent object) page = new UnpublishedContent(pageId, Services); } } // NOTE: The previous previewer had a content node associated with the request, // meaning that an implementation may have used this to traverse the content-tree. // In order to maintain backward-compatibility, we must ensure the PublishedContentRequest context. if (UmbracoContext.PublishedContentRequest == null) { UmbracoContext.PublishedContentRequest = new PublishedContentRequest( Request.RequestUri, UmbracoContext.RoutingContext, UmbracoConfig.For.UmbracoSettings().WebRouting, null) { PublishedContent = page }; } // Set the culture for the preview if (page != null) { var culture = page.GetCulture(); System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; } // Get content node object var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value); // Construct preview model var model = new PreviewModel { Page = page, Item = content, EditorAlias = data.EditorAlias, PreviewViewPath = data.PreviewViewPath, ViewPath = data.ViewPath }; // Render view var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml"; var markup = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext); // Return response var response = new HttpResponseMessage { Content = new StringContent(markup ?? string.Empty) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html); return(response); }
public void Handle(ContentUnpublishedNotification notification) => UnpublishedContent?.Invoke(notification);
public PartialViewResult GetPreviewMarkup([FromForm] PreviewData data, [FromQuery] int pageId) { var page = default(IPublishedContent); // If the page is new, then the ID will be zero if (pageId > 0) { // Get page container node page = _contentQuery.Content(pageId); if (page == null) { // If unpublished, then fake PublishedContent page = new UnpublishedContent(pageId, _contentService, _contentTypeService, _dataTypeService, _propertyEditorCollection, _publishedContentTypeFactory); } } if (_umbracoContext.UmbracoContext.PublishedRequest == null) { var request = _router.CreateRequestAsync(new Uri(Request.GetDisplayUrl())).Result; request.SetPublishedContent(page); _umbracoContext.UmbracoContext.PublishedRequest = request.Build(); } // Set the culture for the preview if (page != null && page.Cultures != null) { var currentCulture = string.IsNullOrWhiteSpace(data.Culture) ? page.GetCultureFromDomains() : data.Culture; if (currentCulture != null && page.Cultures.ContainsKey(currentCulture)) { var culture = new CultureInfo(page.Cultures[currentCulture].Culture); // _umbracoContext.UmbracoContext.PublishedRequest.Culture = culture; // TODO: Not sure if this is needed? System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; _umbracoContext.UmbracoContext.VariationContextAccessor.VariationContext = new VariationContext(culture.Name); } } // Get content node object var content = _dtgeHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value); // Construct preview model var model = new PreviewModel { Page = page, Item = content, EditorAlias = data.EditorAlias, PreviewViewPath = data.PreviewViewPath, ViewPath = data.ViewPath }; // Render view var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml"; var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()); viewData.Model = model; return(new PartialViewResult() { ViewName = partialName, ViewData = viewData }); }
public HttpResponseMessage GetPreviewMarkup([FromBody] PreviewData data, [FromUri] int pageId) { var page = default(IPublishedContent); // If the page is new, then the ID will be zero if (pageId > 0) { // Get page container node page = Umbraco.Content(pageId); if (page == null) { // If unpublished, then fake PublishedContent page = new UnpublishedContent(pageId, Services); } } if (UmbracoContext.PublishedRequest == null) { var router = Current.Factory.GetInstance(typeof(IPublishedRouter)) as IPublishedRouter; UmbracoContext.PublishedRequest = router.CreateRequest(UmbracoContext, Request.RequestUri); UmbracoContext.PublishedRequest.PublishedContent = page; } // Set the culture for the preview if (page != null && page.Cultures != null) { var currentCulture = string.IsNullOrWhiteSpace(data.Culture) ? page.GetCultureFromDomains() : data.Culture; if (currentCulture != null && page.Cultures.ContainsKey(currentCulture)) { var culture = new CultureInfo(page.Cultures[currentCulture].Culture); UmbracoContext.PublishedRequest.Culture = culture; System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; } } // Get content node object var content = DocTypeGridEditorHelper.ConvertValueToContent(data.Id, data.ContentTypeAlias, data.Value); // Construct preview model var model = new PreviewModel { Page = page, Item = content, EditorAlias = data.EditorAlias, PreviewViewPath = data.PreviewViewPath, ViewPath = data.ViewPath }; // Render view var partialName = "~/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditorPreviewer.cshtml"; var markup = Helpers.ViewHelper.RenderPartial(partialName, model, UmbracoContext.HttpContext, UmbracoContext); // Return response var response = new HttpResponseMessage { Content = new StringContent(markup ?? string.Empty) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue(MediaTypeNames.Text.Html); return(response); }