Skip to content

Commit

Permalink
option to add thumbnail (#3746)
Browse files Browse the repository at this point in the history
  • Loading branch information
reshmee011 authored Feb 11, 2024
1 parent f2fe493 commit aa84bc0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
17 changes: 15 additions & 2 deletions documentation/Set-PnPWebHeader.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Allows configuration of the "Change the look" Header
## SYNTAX

```powershell
Set-PnPWebHeader [-SiteLogoUrl <string>] [-HeaderLayout <HeaderLayoutType>] [-HeaderEmphasis <SPVariantThemeType>] [-HideTitleInHeader]
[-HeaderBackgroundImageUrl <string>] [-HeaderBackgroundImageFocalX <double>] [-HeaderBackgroundImageFocalY <double>] [-LogoAlignment <LogoAlignment>]
Set-PnPWebHeader [-SiteLogoUrl <string>] [-SiteThumbnailUrl <string>] [-HeaderLayout <HeaderLayoutType>] [-HeaderEmphasis <SPVariantThemeType>] [-HideTitleInHeader] [-HeaderBackgroundImageUrl <string>] [-HeaderBackgroundImageFocalX <double>] [-HeaderBackgroundImageFocalY <double>] [-LogoAlignment <LogoAlignment>]
[-Connection <PnPConnection>]
```

Expand Down Expand Up @@ -163,6 +162,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -SiteThumbnailUrl
Sets the thumbnail of the site shown at the top left to the provided server relative url, i.e. /sites/hrdepartment/siteassets/thumbnail.png. Provide "" or $null to remove the thumbnail.
```yaml
Type: String
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -HideTitleInHeader
Toggle the title visibility in the header.
Expand Down
32 changes: 22 additions & 10 deletions src/Commands/Web/SetWebHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class SetWebHeader : PnPWebCmdlet
[Parameter(Mandatory = false)]
public string SiteLogoUrl;

[Parameter(Mandatory = false)]
public string SiteThumbnailUrl;

[Parameter(Mandatory = false)]
public HeaderLayoutType HeaderLayout = HeaderLayoutType.Standard;

Expand All @@ -38,18 +41,17 @@ public class SetWebHeader : PnPWebCmdlet
protected override void ExecuteCmdlet()
{
var requiresWebUpdate = false;

if(ParameterSpecified(nameof(SiteLogoUrl)))
{
WriteVerbose($"Setting site logo image to '{SiteLogoUrl}'");

var stringContent = new StringContent("{\"relativeLogoUrl\":\"" + SiteLogoUrl + "\",\"type\":0,\"aspect\":1}");
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
CurrentWeb.EnsureProperties(p => p.Url);
var result = GraphHelper.PostAsync(Connection, $"{CurrentWeb.Url.TrimEnd('/')}/_api/siteiconmanager/setsitelogo", AccessToken, stringContent).GetAwaiter().GetResult();
WriteVerbose($"Response from setsitelogo request: {result.StatusCode}");
}
{
SetSiteImage(SiteLogoUrl, "site logo", 1);
}

if(ParameterSpecified(nameof(SiteThumbnailUrl)))
{
SetSiteImage(SiteThumbnailUrl, "thumbnailurl", 0);
}

if(ParameterSpecified(nameof(LogoAlignment)))
{
WriteVerbose($"Setting site logo alignment to '{LogoAlignment}'");
Expand Down Expand Up @@ -120,5 +122,15 @@ protected override void ExecuteCmdlet()
ClientContext.ExecuteQueryRetry();
}
}
private void SetSiteImage(string imageUrl, string imageType, int aspect)
{
WriteVerbose($"Setting site {imageType} image to '{imageUrl}'");

var stringContent = new StringContent($"{{\"relativeLogoUrl\":\"{imageUrl}\",\"type\":0,\"aspect\":{aspect}}}");
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
CurrentWeb.EnsureProperties(p => p.Url);
var result = GraphHelper.PostAsync(Connection, $"{CurrentWeb.Url.TrimEnd('/')}/_api/siteiconmanager/setsitelogo", AccessToken, stringContent).GetAwaiter().GetResult();
WriteVerbose($"Response from {imageType} request: {result.StatusCode}");
}
}
}

0 comments on commit aa84bc0

Please sign in to comment.