-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Placement match providers #2864
Merged
sebastienros
merged 27 commits into
OrchardCMS:dev
from
KeithRaven:Placement_Match_Providers
Dec 20, 2018
Merged
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8896aa5
corrected typo
BuzzKeith 8cea6ac
ported placement match providers from O1
BuzzKeith 1d1c270
renamed matches to match as not an array
BuzzKeith 98f1041
switch match providers to accept JToken rather than string expression
BuzzKeith 841d85f
tidied up match providers
BuzzKeith 257c581
updated read me
BuzzKeith 2c0bf4c
Merge branch 'placement_matches_dynamic' into placement_matches_dev
BuzzKeith 3b47d2c
Merge branch 'dev' into placement_matches_dev
BuzzKeith 8ce7a00
update path property due to dev changes. Appears to return incorrect…
BuzzKeith 6edc550
Addition of placement match providers
BuzzKeith ee80832
removed unnecessary debug code
BuzzKeith 133548b
removed match node and elevated match providers
BuzzKeith 62976f7
updated filter providers to accept string or array of strings
BuzzKeith 371885c
readme update
BuzzKeith 02f9196
renamed matchproviders to be consistent with oc
BuzzKeith 18f77f9
contentItem already null checked
BuzzKeith 33e79a5
rename of interface in docs
BuzzKeith 5df1d0c
updated naming
BuzzKeith 3caab4d
renamed file
BuzzKeith 5f40364
added path filet provider
BuzzKeith a0f23e7
added path filter to readme
BuzzKeith d9b41ea
removed commented code from O1
BuzzKeith d5677a0
Merge branch 'placement_matches_dec_dev' into Placement_Match_Providers
BuzzKeith 9a67d52
renamed file
BuzzKeith 124cab2
tidied path normalisation
BuzzKeith 294eb40
moved content filters form OrchardCore.Contents to OrchardCore.Conten…
BuzzKeith bba33a2
updated PlacementFile to switch DisplayType from using kebab to camel…
BuzzKeith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...OrchardCore.Modules/OrchardCore.Contents/Placement/DefaultPlacementParseMatchProviders.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,94 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using OrchardCore.ContentManagement; | ||
using OrchardCore.DisplayManagement.Descriptors; | ||
using OrchardCore.DisplayManagement.Descriptors.ShapePlacementStrategy; | ||
using OrchardCore.DisplayManagement.Shapes; | ||
|
||
namespace OrchardCore.Contents.Placement | ||
{ | ||
public enum MatchType | ||
{ | ||
Any, | ||
All | ||
} | ||
|
||
public class ContentPartPlacementParseMatchOptions | ||
{ | ||
[JsonProperty(PropertyName = "parts")] | ||
public IEnumerable<string> Parts { get; set; } | ||
|
||
[JsonProperty(PropertyName = "matchType")] | ||
public MatchType MatchType { get; set; } | ||
} | ||
|
||
public class ContentPartPlacementParseMatchProvider : ContentPlacementParseMatchProviderBase, IPlacementParseMatchProvider | ||
{ | ||
public string Key { get { return "contentPart"; } } | ||
|
||
public bool Match(ShapePlacementContext context, JToken expression) | ||
{ | ||
var contentItem = GetContent(context); | ||
if (contentItem == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var options = expression.ToObject<ContentPartPlacementParseMatchOptions>(); | ||
|
||
return options.MatchType == MatchType.All ? options.Parts.All(p => contentItem.Has(p)) : options.Parts.Any(p => contentItem.Has(p)); | ||
} | ||
} | ||
|
||
public class ContentTypePlacementParseMatchProvider : ContentPlacementParseMatchProviderBase, IPlacementParseMatchProvider | ||
{ | ||
public string Key { get { return "contentType"; } } | ||
|
||
public bool Match(ShapePlacementContext context, JToken expression) | ||
{ | ||
var contentItem = GetContent(context); | ||
if (contentItem == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var contentTypes = expression.ToObject<IEnumerable<string>>(); | ||
|
||
return contentTypes.Any(ct => | ||
{ | ||
if (ct.EndsWith("*")) | ||
{ | ||
var prefix = ct.Substring(0, ct.Length - 1); | ||
|
||
return (contentItem?.ContentType ?? "").StartsWith(prefix);// || (context.Stereotype ?? "").StartsWith(prefix); | ||
} | ||
|
||
return contentItem.ContentType == ct;// || context.Stereotype == expression; | ||
}); | ||
} | ||
} | ||
|
||
public class ContentPlacementParseMatchProviderBase | ||
{ | ||
protected bool HasContent(ShapePlacementContext context) | ||
{ | ||
var shape = context.ZoneShape as Shape; | ||
return shape != null && shape.Properties["ContentItem"] != null; | ||
} | ||
|
||
protected ContentItem GetContent(ShapePlacementContext context) | ||
{ | ||
if (!HasContent(context)) | ||
{ | ||
return null; | ||
} | ||
|
||
var shape = context.ZoneShape as Shape; | ||
return shape.Properties["ContentItem"] as ContentItem; | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...Core.DisplayManagement/Descriptors/ShapePlacementStrategy/IPlacementParseMatchProvider.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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace OrchardCore.DisplayManagement.Descriptors.ShapePlacementStrategy | ||
{ | ||
public interface IPlacementParseMatchProvider | ||
{ | ||
string Key { get; } | ||
bool Match(ShapePlacementContext context, JToken expression); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
match
is necessary. Every filter can be a the root of the node, likedisplay-type
ordifferentiator
.I would also accept a string, and array of string, of a complex object (for
matchType
). You could even simplify it by not takingmatchType
at all, as i assume we'll always want 'any'. I can't find an example that someone would want to match on having multiple parts on the content item.ContentType can also accept multiple values in this case, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of loosing the "match" node in that the matches are doing the same kind of thing (i.e. filtering) as display-type and differentiator as so they would be better together.
That said I personally find it a little confusing having the filters and alterations (place,wrappers, alternates, shape) alongside each other with nothing to distinguish them but I guess it keeps it simpler.
Yes allowing string, array string or object would be a good idea as well.
I haven't got a use case at the minute but it feels like there one out there somewhere :) It's not necessary to supply it as it defaults to "Any".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe confusing, but only because you are coming from O1, and as long as it's document it should not be an issue.