-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IShapePlacementProvider and ShapeTablePlacementProvider (#6780)
- Loading branch information
Showing
10 changed files
with
171 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/OrchardCore/OrchardCore.DisplayManagement/Descriptors/ShapeTablePlacementProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Threading.Tasks; | ||
using OrchardCore.DisplayManagement.Handlers; | ||
using OrchardCore.DisplayManagement.Theming; | ||
|
||
namespace OrchardCore.DisplayManagement.Descriptors | ||
{ | ||
public class ShapeTablePlacementProvider : IShapePlacementProvider | ||
{ | ||
private readonly IShapeTableManager _shapeTableManager; | ||
private readonly IThemeManager _themeManager; | ||
|
||
public ShapeTablePlacementProvider( | ||
IShapeTableManager shapeTableManager, | ||
IThemeManager themeManager | ||
) | ||
{ | ||
_shapeTableManager = shapeTableManager; | ||
_themeManager = themeManager; | ||
} | ||
|
||
public async Task<IPlacementInfoResolver> BuildPlacementInfoResolverAsync(IBuildShapeContext context) | ||
{ | ||
var theme = await _themeManager.GetThemeAsync(); | ||
|
||
// If there is no active theme, do nothing | ||
if (theme == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var shapeTable = _shapeTableManager.GetShapeTable(theme.Id); | ||
|
||
return new ShapeTablePlacementResolver(shapeTable); | ||
} | ||
|
||
private class ShapeTablePlacementResolver : IPlacementInfoResolver | ||
{ | ||
private readonly ShapeTable _shapeTable; | ||
|
||
internal ShapeTablePlacementResolver(ShapeTable shapeTable) | ||
{ | ||
_shapeTable = shapeTable; | ||
} | ||
|
||
public PlacementInfo ResolvePlacement(ShapePlacementContext placementContext) | ||
{ | ||
if (_shapeTable.Descriptors.TryGetValue(placementContext.ShapeType, out var descriptor)) | ||
{ | ||
var placement = descriptor.Placement(placementContext); | ||
if (placement != null) | ||
{ | ||
placement.Source = placementContext.Source; | ||
return placement; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/OrchardCore/OrchardCore.DisplayManagement/Handlers/FindPlacementDelegate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
using OrchardCore.DisplayManagement.Descriptors; | ||
using OrchardCore.DisplayManagement.Descriptors; | ||
|
||
namespace OrchardCore.DisplayManagement.Handlers | ||
{ | ||
/// <summary> | ||
/// A function that provides a <see cref="PlacementInfo"/> instance for a shape. | ||
/// </summary> | ||
/// <param name="shape">The shape to render.</param> | ||
/// <param name="shapeType">The shape type to render.</param> | ||
/// <param name="differentiator"> | ||
/// A discriminator that differentiates this specific shape to the others of the same type. | ||
/// For instance multiple field shape smight be displayed in different locations even though | ||
/// they are of the same type. | ||
/// </param> | ||
/// <param name="displayType">The display type the content item owning the shape is rendered with.</param> | ||
/// <param name="context">The <see cref="IBuildShapeContext"/> in which the shape is placed.</param> | ||
/// <returns>The <see cref="PlacementInfo"/> to use or <see cref="null"/> if this function is not concerned.</returns> | ||
public delegate PlacementInfo FindPlacementDelegate(string shapeType, string differentiator, string displayType, IBuildShapeContext context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters