Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to add thumbnail. closes #3736 #3746

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}");
}
}
}
Loading