Repository navigation
Open
Labels
Candidate for fixingP1area: pages API πWorking with modern pageshelp wantedExtra attention is needed
Description
Improved support for setting image properties by supporting all the available options in
pnpcore/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs
Lines 2844 to 2935 in 89bd037
| public async Task<string> GetInlineImageAsync(IPageText textEditorInstance, string serverRelativeUrl, PageImageOptions imageOptions = null) | |
| { | |
| if (EditorType == EditorType.CK4 && textEditorInstance == null) | |
| { | |
| throw new ArgumentNullException(nameof(textEditorInstance)); | |
| } | |
| if (string.IsNullOrEmpty(serverRelativeUrl)) | |
| { | |
| throw new ArgumentNullException(nameof(serverRelativeUrl)); | |
| } | |
| if (imageOptions == null) | |
| { | |
| imageOptions = new PageImageOptions | |
| { | |
| IsInlineImage = true, | |
| }; | |
| } | |
| else | |
| { | |
| imageOptions.IsInlineImage = true; | |
| } | |
| if (EditorType == EditorType.CK4) | |
| { | |
| var inlineImageWebPart = await GetImageWebPartAsync(serverRelativeUrl, imageOptions).ConfigureAwait(false); | |
| (inlineImageWebPart as PageWebPart).RichTextEditorInstanceId = textEditorInstance.InstanceId.ToString(); | |
| // Add the image web part to collection of inline web parts | |
| (textEditorInstance as PageText).InlineWebParts.Add(inlineImageWebPart as PageWebPart); | |
| // Prepare the text snippet to insert | |
| string alignmentValue = "webPartInRteAlignLeft"; | |
| if (imageOptions != null) | |
| { | |
| if (imageOptions.Alignment == PageImageAlignment.Center) | |
| { | |
| alignmentValue = "webPartInRteAlignCenter"; | |
| } | |
| else if (imageOptions.Alignment == PageImageAlignment.Right) | |
| { | |
| alignmentValue = "webPartInRteAlignRight"; | |
| } | |
| } | |
| return inlineImageCK4Html.Replace(inlineImageTextControl, inlineImageWebPart.InstanceId.ToString()) | |
| .Replace(inlineImageAlignment, alignmentValue); | |
| } | |
| else | |
| { | |
| // Find the server relative image | |
| var image = await PnPContext.Web.GetFileByServerRelativeUrlAsync(serverRelativeUrl, p => p.UniqueId, p => p.ListId).ConfigureAwait(false); | |
| // Set defaults in case height and width are not set | |
| if (!imageOptions.Height.HasValue) | |
| { | |
| // Assume by default 0, aligned with the SPO behavior | |
| imageOptions.Height = 0; | |
| } | |
| if (!imageOptions.Width.HasValue) | |
| { | |
| // Assume by default 0, aligned with the SPO behavior | |
| imageOptions.Width = 0; | |
| } | |
| if (!imageOptions.WidthPercentage.HasValue) | |
| { | |
| // Assume by default 100% of the editor width, aligned with the SPO behavior | |
| imageOptions.WidthPercentage = 100; | |
| } | |
| imageOptions.Link ??= ""; | |
| imageOptions.Caption ??= ""; | |
| imageOptions.AlternativeText ??= ""; | |
| return inlineImageCK5Html.Replace(inlineImageUrl, serverRelativeUrl) | |
| .Replace(inlineImageAlignment, imageOptions.Alignment.ToString()) | |
| .Replace(inlineImageCaption, imageOptions.Caption) | |
| .Replace(inlineImageAlternativeText, imageOptions.AlternativeText) | |
| .Replace(inlineImageLinkUrl, imageOptions.Link) | |
| .Replace(inlineImageWidth, imageOptions.Width.Value.ToString()) | |
| .Replace(inlineImageHeight, imageOptions.Height.Value.ToString()) | |
| .Replace(inlineWidthPercentage, imageOptions.WidthPercentage.Value.ToString()) | |
| .Replace(inlineWebId, PnPContext.Web.Id.ToString()) | |
| .Replace(inlineSiteId, PnPContext.Site.Id.ToString()) | |
| .Replace(inlineListId, image.ListId.ToString()) | |
| .Replace(inlineUniqueId, image.UniqueId.ToString()); | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
Candidate for fixingP1area: pages API πWorking with modern pageshelp wantedExtra attention is needed

Activity