-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Html/Picture on mocked Item #3141
- Loading branch information
1 parent
9551da9
commit 9e3ebb3
Showing
11 changed files
with
115 additions
and
81 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
26 changes: 26 additions & 0 deletions
26
Src/Sxc/ToSic.Sxc/Data/Factory/CodeDataFactoryExtensions.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,26 @@ | ||
using System.Runtime.CompilerServices; | ||
using System; | ||
using ToSic.Sxc.Services; | ||
using ToSic.Sxc.Code; | ||
|
||
namespace ToSic.Sxc.Data | ||
{ | ||
internal static class CodeDataFactoryExtensions | ||
{ | ||
/// <summary> | ||
/// Will check if the CodeDataFactory exists and try to get the ServiceKit - or throw an error. | ||
/// </summary> | ||
/// <exception cref="NotSupportedException"></exception> | ||
internal static ServiceKit16 GetServiceKitOrThrow(this CodeDataFactory cdf, [CallerMemberName] string cName = default) | ||
{ | ||
if (cdf == null) | ||
throw new NotSupportedException( | ||
$"Trying to use {cName}(...) in a scenario where the {nameof(cdf)} is not available."); | ||
|
||
var kit = cdf._DynCodeRoot.GetKit<ServiceKit16>(); | ||
return kit ?? throw new NotSupportedException( | ||
$"Trying to use {cName}(...) in a scenario where the {nameof(ServiceKit16)} is not available."); | ||
} | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using ToSic.Eav.Plumbing; | ||
using ToSic.Razor.Blade; | ||
using ToSic.Sxc.Images; | ||
using static ToSic.Eav.Parameters; | ||
|
||
namespace ToSic.Sxc.Data.Typed | ||
{ | ||
internal class TypedItemHelpers | ||
{ | ||
public static IHtmlTag Html( | ||
CodeDataFactory cdf, | ||
ITypedItem item, | ||
string name, | ||
string noParamOrder, | ||
object container, | ||
bool? toolbar, | ||
object imageSettings, | ||
bool? required, | ||
bool debug | ||
) | ||
{ | ||
Protect(noParamOrder, $"{nameof(container)}, {nameof(imageSettings)}, {nameof(toolbar)}, {nameof(required)}, {nameof(debug)}..."); | ||
var kit = cdf.GetServiceKitOrThrow(); | ||
var field = item.Field(name, required: required); | ||
return kit.Cms.Html(field, container: container, classes: null, imageSettings: imageSettings, debug: debug, toolbar: toolbar); | ||
} | ||
|
||
public static IResponsivePicture Picture( | ||
CodeDataFactory cdf, | ||
ITypedItem item, | ||
string name, | ||
string noParamOrder, | ||
object settings, | ||
object factor, | ||
object width, | ||
string imgAlt, | ||
string imgAltFallback, | ||
string imgClass, | ||
object recipe | ||
) | ||
{ | ||
Protect(noParamOrder, $"{nameof(settings)}, {nameof(factor)}, {nameof(width)}, {nameof(imgAlt)}..."); | ||
var kit = cdf.GetServiceKitOrThrow(); | ||
var field = item.Field(name, required: true); | ||
return field.Url.IsEmptyOrWs() | ||
? null | ||
: kit.Image.Picture(field, settings: settings, factor: factor, width: width, imgAlt: imgAlt, imgAltFallback: imgAltFallback, imgClass: imgClass, recipe: recipe); | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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