Skip to content
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added the ability to `Get-PnPPage` to return all site pages in the site by omitting the `-Identity` parameter [#4805](https://github.com/pnp/powershell/pull/4805)
- Added `Copy-PnPPage`, `Move-PnPPage` and `Get-PnPPageCopyProgress` cmdlets to allow for copying and moving site pages between sites [#4806](https://github.com/pnp/powershell/pull/4806)
- Added `Get-PnPBrandCenterConfig` to retrieve the configuration of the Brand Center on the tenant [#4830](https://github.com/pnp/powershell/pull/4830)
- Added `Get-PnPBrandCenterFont` to retrieve the available fonts from the various Brand Centers [#4830](https://github.com/pnp/powershell/pull/4830)
- Added `Use-PnPBrandCenterFont` to apply the specified font from the Brand Center to the current site [#4830](https://github.com/pnp/powershell/pull/4830)
- Added `Get-PnPBrandCenterFontPackage` to retrieve the available font packages from the various Brand Centers [#4830](https://github.com/pnp/powershell/pull/4830)
- Added `Use-PnPBrandCenterFontPackage` to apply the specified font package from the Brand Center to the current site [#4830](https://github.com/pnp/powershell/pull/4830)
- Added `Add-PnPBrandCenterFont` to upload a font to the tenant Brand Center [#4830](https://github.com/pnp/powershell/pull/4830)

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPBrandCenterFont.html
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPBrandCenterFontPackage.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPBrandCenterFont
title: Get-PnPBrandCenterFontPackage
---

# Get-PnPBrandCenterFont
# Get-PnPBrandCenterFontPackage

## SYNOPSIS
Returns the available fonts configured throught heBrand Center
Expand All @@ -16,12 +16,12 @@ Returns the available fonts configured throught heBrand Center

### All
```powershell
Get-PnPBrandCenterFont [-Store <Tenant|OutOfBox|Site|All>] [-Connection <PnPConnection>]
Get-PnPBrandCenterFontPackage [-Store <Tenant|OutOfBox|Site|All>] [-Connection <PnPConnection>]
```

### Single
```powershell
Get-PnPBrandCenterFont -Identity <BrandCenterFontPipeBind> [-Store <Tenant|OutOfBox|Site|All>] [-Connection <PnPConnection>]
Get-PnPBrandCenterFontPackage -Identity <BrandCenterFontPipeBind> [-Store <Tenant|OutOfBox|Site|All>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand All @@ -31,28 +31,28 @@ Allows retrieval of the available fonts from the various Brand Centers.

### EXAMPLE 1
```powershell
Get-PnPBrandCenterFont
Get-PnPBrandCenterFontPackage
```

Returns all the available fonts

### EXAMPLE 2
```powershell
Get-PnPBrandCenterFont -Store Site
Get-PnPBrandCenterFontPackage -Store Site
```

Returns the available fonts from the site collection Brand Center

### EXAMPLE 3
```powershell
Get-PnPBrandCenterFont -Identity "My awesome font"
Get-PnPBrandCenterFontPackage -Identity "My awesome font"
```

Looks up and returns the font with the name "My awesome font" from any of the Brand Centers

### EXAMPLE 4
```powershell
Get-PnPBrandCenterFont -Identity "2812cbd8-7176-4e45-8911-6a063f89a1f1"
Get-PnPBrandCenterFontPackage -Identity "2812cbd8-7176-4e45-8911-6a063f89a1f1"
```

Looks up and returns the font with the Identity "2812cbd8-7176-4e45-8911-6a063f89a1f1" from any of the Brand Centers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Use-PnPBrandCenterFont.html
online version: https://pnp.github.io/powershell/cmdlets/Use-PnPBrandCenterFontPackage.html
external help file: PnP.PowerShell.dll-Help.xml
title: Use-PnPBrandCenterFont
title: Use-PnPBrandCenterFontPackage
---

# Use-PnPBrandCenterFont
# Use-PnPBrandCenterFontPackage

## SYNOPSIS
Applies the specified font from the Brand Center to the current site.

## SYNTAX

```powershell
Use-PnPBrandCenterFont -Identity <BrandCenterFontPipeBind> [-Store <Tenant|OutOfBox|Site|All>] [-Connection <PnPConnection>]
Use-PnPBrandCenterFontPackage -Identity <BrandCenterFontPipeBind> [-Store <Tenant|OutOfBox|Site|All>] [-Connection <PnPConnection>]
```

## DESCRIPTION
Expand All @@ -25,14 +25,14 @@ Applies the specified font from the Brand Center to the current site.

### EXAMPLE 1
```powershell
Use-PnPBrandCenterFont -Identity "2812cbd8-7176-4e45-8911-6a063f89a1f1"
Use-PnPBrandCenterFontPackage -Identity "2812cbd8-7176-4e45-8911-6a063f89a1f1"
```

Looks up and applies the font with the identity "2812cbd8-7176-4e45-8911-6a063f89a1f1" from any of the Brand Centers to the current site

### EXAMPLE 2
```powershell
Use-PnPBrandCenterFont -Identity "My awesome font" -Store Tenant
Use-PnPBrandCenterFontPackage -Identity "My awesome font" -Store Tenant
```

Looks up and applies the font with the title "My awesome font" from the tenant Brand Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace PnP.PowerShell.Commands.Base.Completers
{
public sealed class BrandCenterFontCompleter : PnPArgumentCompleter
public sealed class BrandCenterFontPackageCompleter : PnPArgumentCompleter
{
protected override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
{
ClientContext.Web.EnsureProperty(w => w.Url);
var fonts = BrandCenterUtility.GetFonts(null, ClientContext, ClientContext.Web.Url);
var fonts = BrandCenterUtility.GetFontPackages(null, ClientContext, ClientContext.Web.Url);
return fonts.Select(font => new CompletionResult(font.Title)).OrderBy(ct => ct.CompletionText);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Base/PipeBinds/BrandCenterFontPipeBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public Font GetFont(BasePSCmdlet cmdlet, ClientContext clientContext, string web
}
else if (_id.HasValue)
{
_font = BrandCenterUtility.GetFontById(cmdlet, clientContext, _id.Value, webUrl, store);
_font = BrandCenterUtility.GetFontPackageById(cmdlet, clientContext, _id.Value, webUrl, store);
return _font;
}
else if (!string.IsNullOrEmpty(_title))
{
_font = BrandCenterUtility.GetFontByTitle(cmdlet, clientContext, _title, webUrl, store);
_font = BrandCenterUtility.GetFontPackageByTitle(cmdlet, clientContext, _title, webUrl, store);
return _font;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

namespace PnP.PowerShell.Commands.Branding
{
[Cmdlet(VerbsCommon.Get, "PnPBrandCenterFont", DefaultParameterSetName = ParameterSet_ALL)]
[Cmdlet(VerbsCommon.Get, "PnPBrandCenterFontPackage", DefaultParameterSetName = ParameterSet_ALL)]
[OutputType(typeof(Font), ParameterSetName = new[] { ParameterSet_SINGLE })]
[OutputType(typeof(IEnumerable<Font>), ParameterSetName = new[] { ParameterSet_ALL })]
public class GetBrandCenterFont : PnPWebCmdlet
public class GetBrandCenterFontPackage : PnPWebCmdlet
{
private const string ParameterSet_SINGLE = "Single";
private const string ParameterSet_ALL = "All";

[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = ParameterSet_SINGLE)]
[ArgumentCompleter(typeof(BrandCenterFontCompleter))]
[ArgumentCompleter(typeof(BrandCenterFontPackageCompleter))]
public BrandCenterFontPipeBind Identity { get; set; }

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_SINGLE)]
Expand All @@ -35,7 +35,7 @@ protected override void ExecuteCmdlet()
}
else
{
WriteObject(BrandCenterUtility.GetFonts(this, ClientContext, CurrentWeb.Url, Store), true);
WriteObject(BrandCenterUtility.GetFontPackages(this, ClientContext, CurrentWeb.Url, Store), true);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Branding/SetBrandCenterFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class SetBrandCenterFont : PnPWebCmdlet
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
[ArgumentCompleter(typeof(BrandCenterFontCompleter))]
[ArgumentCompleter(typeof(BrandCenterFontPackageCompleter))]
public BrandCenterFontPipeBind Identity { get; set; }

[Parameter(Mandatory = true)]
Expand All @@ -38,12 +38,12 @@
brandCenterContext.ExecuteQueryRetry();

LogDebug($"Uploading the font to the Brand Center font library root folder at {brandCenterFontLibrary.RootFolder.ServerRelativeUrl}");
var file = brandCenterFontLibrary.RootFolder.UploadFile(System.IO.Path.GetFileName(Path), Path, true);

Check failure on line 41 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

The name 'Path' does not exist in the current context

Check failure on line 41 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

The name 'Path' does not exist in the current context

Check failure on line 41 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

The name 'Path' does not exist in the current context

Check failure on line 41 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

The name 'Path' does not exist in the current context

if (ParameterSpecified(nameof(Visible)) && Visible.HasValue)

Check failure on line 43 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'bool' does not contain a definition for 'HasValue' and no accessible extension method 'HasValue' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 43 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'bool' does not contain a definition for 'HasValue' and no accessible extension method 'HasValue' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)
{
LogDebug($"Setting the font visibility to {Visible.Value}");

Check failure on line 45 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'bool' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 45 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'bool' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)
ListItemHelper.SetFieldValues(file.ListItemAllFields, new Hashtable { { "_SPFontVisible", Visible.Value ? "True" : "False" } }, this);

Check failure on line 46 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'bool' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 46 in src/Commands/Branding/SetBrandCenterFont.cs

View workflow job for this annotation

GitHub Actions / build_dev_branch

'bool' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)
file.ListItemAllFields.UpdateOverwriteVersion();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace PnP.PowerShell.Commands.Branding
{
[Cmdlet(VerbsOther.Use, "PnPBrandCenterFont")]
[Cmdlet(VerbsOther.Use, "PnPBrandCenterFontPackage")]
[OutputType(typeof(void))]
public class UseBrandCenterFont : PnPWebCmdlet
public class UseBrandCenterFontPackage : PnPWebCmdlet
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
[ArgumentCompleter(typeof(BrandCenterFontCompleter))]
[ArgumentCompleter(typeof(BrandCenterFontPackageCompleter))]
public BrandCenterFontPipeBind Identity { get; set; }

[Parameter(Mandatory = false)]
Expand All @@ -31,7 +31,7 @@ protected override void ExecuteCmdlet()
LogWarning($"The font with identity {font.Id} titled '{font.Title}' is not valid. Will try to apply it anyway.");
}

var url = $"{BrandCenterUtility.GetStoreUrlByStoreType(font.Store, CurrentWeb.Url)}/GetById('{font.Id}')/Apply";
var url = $"{BrandCenterUtility.GetStoreFontPackageUrlByStoreType(font.Store, CurrentWeb.Url)}/GetById('{font.Id}')/Apply";
LogDebug($"Applying font by making a POST call to {url}");
RestHelper.Post(Connection.HttpClient, url, ClientContext);
}
Expand Down
40 changes: 20 additions & 20 deletions src/Commands/Utilities/BrandCenterUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ namespace PnP.PowerShell.Commands.Utilities
internal static class BrandCenterUtility
{
/// <summary>
/// Retrieves a font from the Brand Center based on its name and optionally store type.
/// Retrieves a font package from the Brand Center based on its name and optionally store type.
/// </summary>
/// <param name="cmdlet">Cmdlet for which this runs, used for logging</param>
/// <param name="title">Title of the font to retrieve</param>
/// <param name="webUrl">Url to use to check the site collection Brand Center</param>
/// <param name="store">The store to check for the font. When NULL, it will check all stores.</param>
/// <param name="clientContext">ClientContext to use to communicate with SharePoint Online</param>
/// <returns>The font with the provided identity or NULL if no font found with the provided identity</returns>
public static Font GetFontByTitle(BasePSCmdlet cmdlet, ClientContext clientContext, string title, string webUrl, Store store = Store.All)
public static Font GetFontPackageByTitle(BasePSCmdlet cmdlet, ClientContext clientContext, string title, string webUrl, Store store = Store.All)
{
if (store == Store.All)
{
return GetFontByTitle(cmdlet, clientContext, title, webUrl, Store.Site) ??
GetFontByTitle(cmdlet, clientContext, title, webUrl, Store.Tenant) ??
GetFontByTitle(cmdlet, clientContext, title, webUrl, Store.OutOfBox);
return GetFontPackageByTitle(cmdlet, clientContext, title, webUrl, Store.Site) ??
GetFontPackageByTitle(cmdlet, clientContext, title, webUrl, Store.Tenant) ??
GetFontPackageByTitle(cmdlet, clientContext, title, webUrl, Store.OutOfBox);
}

var url = $"{GetStoreUrlByStoreType(store, webUrl)}/GetByTitle('{title}')";
var url = $"{GetStoreFontPackageUrlByStoreType(store, webUrl)}/GetByTitle('{title}')";
cmdlet?.LogDebug($"Making a GET request to {url} to retrieve {store} font with title {title}.");
try
{
Expand All @@ -52,24 +52,24 @@ public static Font GetFontByTitle(BasePSCmdlet cmdlet, ClientContext clientConte
}

/// <summary>
/// Retrieves a font from the Brand Center based on its identity and optionally store type.
/// Retrieves a font package from the Brand Center based on its identity and optionally store type.
/// </summary>
/// <param name="cmdlet">Cmdlet for which this runs, used for logging</param>
/// <param name="identity">Id of the font to retrieve</param>
/// <param name="webUrl">Url to use to check the site collection Brand Center</param>
/// <param name="store">The store to check for the font. When NULL, it will check all stores.</param>
/// <param name="clientContext">ClientContext to use to communicate with SharePoint Online</param>
/// <returns>The font with the provided identity or NULL if no font found with the provided identity</returns>
public static Font GetFontById(BasePSCmdlet cmdlet, ClientContext clientContext, Guid identity, string webUrl, Store store = Store.All)
public static Font GetFontPackageById(BasePSCmdlet cmdlet, ClientContext clientContext, Guid identity, string webUrl, Store store = Store.All)
{
if (store == Store.All)
{
return GetFontById(cmdlet, clientContext, identity, webUrl, Store.Site) ??
GetFontById(cmdlet, clientContext, identity, webUrl, Store.Tenant) ??
GetFontById(cmdlet, clientContext, identity, webUrl, Store.OutOfBox);
return GetFontPackageById(cmdlet, clientContext, identity, webUrl, Store.Site) ??
GetFontPackageById(cmdlet, clientContext, identity, webUrl, Store.Tenant) ??
GetFontPackageById(cmdlet, clientContext, identity, webUrl, Store.OutOfBox);
}

var url = $"{GetStoreUrlByStoreType(store, webUrl)}/GetById('{identity}')";
var url = $"{GetStoreFontPackageUrlByStoreType(store, webUrl)}/GetById('{identity}')";
cmdlet?.LogDebug($"Making a GET request to {url} to retrieve {store} font with identity {identity}.");
try
{
Expand All @@ -89,38 +89,38 @@ public static Font GetFontById(BasePSCmdlet cmdlet, ClientContext clientContext,
}

/// <summary>
/// Retrieves fonts from the Brand Center optionally based on the store type.
/// Retrieves font packages from the Brand Center optionally based on the store type.
/// </summary>
/// <param name="cmdlet">Cmdlet for which this runs, used for logging</param>
/// <param name="webUrl">Url to use to check the site collection Brand Center</param>
/// <param name="store">The store to check for the font. When NULL, it will check all stores.</param>
/// <param name="clientContext">ClientContext to use to communicate with SharePoint Online</param>
/// <returns>The available fonts</returns>
public static List<Font> GetFonts(BasePSCmdlet cmdlet, ClientContext clientContext, string webUrl, Store store = Store.All)
public static List<Font> GetFontPackages(BasePSCmdlet cmdlet, ClientContext clientContext, string webUrl, Store store = Store.All)
{
if (store == Store.All)
{
var allStoresFonts = new List<Font>();
allStoresFonts.AddRange(GetFonts(cmdlet, clientContext, webUrl, Store.Site));
allStoresFonts.AddRange(GetFonts(cmdlet, clientContext, webUrl, Store.Tenant));
allStoresFonts.AddRange(GetFonts(cmdlet, clientContext, webUrl, Store.OutOfBox));
allStoresFonts.AddRange(GetFontPackages(cmdlet, clientContext, webUrl, Store.Site));
allStoresFonts.AddRange(GetFontPackages(cmdlet, clientContext, webUrl, Store.Tenant));
allStoresFonts.AddRange(GetFontPackages(cmdlet, clientContext, webUrl, Store.OutOfBox));
return allStoresFonts;
}

var url = GetStoreUrlByStoreType(store, webUrl);
var url = GetStoreFontPackageUrlByStoreType(store, webUrl);
cmdlet?.LogDebug($"Making a GET request to {url} to retrieve {store} fonts.");
var fonts = RestHelper.Get<RestResultCollection<Font>>(Framework.Http.PnPHttpClient.Instance.GetHttpClient(), url, clientContext);
return fonts.Items.ToList();
}

/// <summary>
/// Returns the URL to the Brand Center based on the store type
/// Returns the font package URL to the Brand Center based on the store type
/// </summary>
/// <param name="store">Brand Center store to connect to</param>
/// <param name="webUrl">Base URL to connect to</param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if an invalid store type has been provided</exception>
public static string GetStoreUrlByStoreType(Store store, string webUrl)
public static string GetStoreFontPackageUrlByStoreType(Store store, string webUrl)
{
return store switch
{
Expand Down
Loading