Skip to content

Commit 4d6a5e7

Browse files
committed
option to add thumbnail
1 parent f2fe493 commit 4d6a5e7

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

documentation/Set-PnPWebHeader.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Allows configuration of the "Change the look" Header
1515
## SYNTAX
1616

1717
```powershell
18-
Set-PnPWebHeader [-SiteLogoUrl <string>] [-HeaderLayout <HeaderLayoutType>] [-HeaderEmphasis <SPVariantThemeType>] [-HideTitleInHeader]
19-
[-HeaderBackgroundImageUrl <string>] [-HeaderBackgroundImageFocalX <double>] [-HeaderBackgroundImageFocalY <double>] [-LogoAlignment <LogoAlignment>]
18+
Set-PnPWebHeader [-SiteLogoUrl <string>] [-SiteThumbnailUrl <string>] [-HeaderLayout <HeaderLayoutType>] [-HeaderEmphasis <SPVariantThemeType>] [-HideTitleInHeader] [-HeaderBackgroundImageUrl <string>] [-HeaderBackgroundImageFocalX <double>] [-HeaderBackgroundImageFocalY <double>] [-LogoAlignment <LogoAlignment>]
2019
[-Connection <PnPConnection>]
2120
```
2221

@@ -163,6 +162,20 @@ Accept pipeline input: False
163162
Accept wildcard characters: False
164163
```
165164
165+
### -SiteThumbnailUrl
166+
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.
167+
168+
```yaml
169+
Type: String
170+
Parameter Sets: (All)
171+
172+
Required: False
173+
Position: Named
174+
Default value: None
175+
Accept pipeline input: False
176+
Accept wildcard characters: False
177+
```
178+
166179
### -HideTitleInHeader
167180
Toggle the title visibility in the header.
168181

src/Commands/Web/SetWebHeader.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public class SetWebHeader : PnPWebCmdlet
1414
[Parameter(Mandatory = false)]
1515
public string SiteLogoUrl;
1616

17+
[Parameter(Mandatory = false)]
18+
public string SiteThumbnailUrl;
19+
1720
[Parameter(Mandatory = false)]
1821
public HeaderLayoutType HeaderLayout = HeaderLayoutType.Standard;
1922

@@ -38,18 +41,17 @@ public class SetWebHeader : PnPWebCmdlet
3841
protected override void ExecuteCmdlet()
3942
{
4043
var requiresWebUpdate = false;
41-
44+
4245
if(ParameterSpecified(nameof(SiteLogoUrl)))
43-
{
44-
WriteVerbose($"Setting site logo image to '{SiteLogoUrl}'");
45-
46-
var stringContent = new StringContent("{\"relativeLogoUrl\":\"" + SiteLogoUrl + "\",\"type\":0,\"aspect\":1}");
47-
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
48-
CurrentWeb.EnsureProperties(p => p.Url);
49-
var result = GraphHelper.PostAsync(Connection, $"{CurrentWeb.Url.TrimEnd('/')}/_api/siteiconmanager/setsitelogo", AccessToken, stringContent).GetAwaiter().GetResult();
50-
WriteVerbose($"Response from setsitelogo request: {result.StatusCode}");
51-
}
46+
{
47+
SetSiteImage(SiteLogoUrl, "site logo", 1);
48+
}
5249

50+
if(ParameterSpecified(nameof(SiteThumbnailUrl)))
51+
{
52+
SetSiteImage(SiteThumbnailUrl, "thumbnailurl", 0);
53+
}
54+
5355
if(ParameterSpecified(nameof(LogoAlignment)))
5456
{
5557
WriteVerbose($"Setting site logo alignment to '{LogoAlignment}'");
@@ -120,5 +122,15 @@ protected override void ExecuteCmdlet()
120122
ClientContext.ExecuteQueryRetry();
121123
}
122124
}
125+
private void SetSiteImage(string imageUrl, string imageType, int aspect)
126+
{
127+
WriteVerbose($"Setting site {imageType} image to '{imageUrl}'");
128+
129+
var stringContent = new StringContent($"{{\"relativeLogoUrl\":\"{imageUrl}\",\"type\":0,\"aspect\":{aspect}}}");
130+
stringContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
131+
CurrentWeb.EnsureProperties(p => p.Url);
132+
var result = GraphHelper.PostAsync(Connection, $"{CurrentWeb.Url.TrimEnd('/')}/_api/siteiconmanager/setsitelogo", AccessToken, stringContent).GetAwaiter().GetResult();
133+
WriteVerbose($"Response from {imageType} request: {result.StatusCode}");
134+
}
123135
}
124136
}

0 commit comments

Comments
 (0)