mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Added support for reusing the same field in a single snippet file.
This commit is contained in:
parent
e5bb771be1
commit
37550593d4
@ -8,7 +8,7 @@ using Orchard.Localization;
|
||||
namespace Orchard.Layouts.Helpers {
|
||||
public static class SnippetHtmlExtensions {
|
||||
|
||||
public static SnippetFieldDescriptorBuilder SnippetField(this HtmlHelper htmlHelper, string name, string type) {
|
||||
public static SnippetFieldDescriptorBuilder SnippetField(this HtmlHelper htmlHelper, string name, string type = null) {
|
||||
var shape = (dynamic) htmlHelper.ViewData.Model;
|
||||
|
||||
return new SnippetFieldDescriptorBuilder(shape)
|
||||
|
@ -141,7 +141,10 @@ namespace Orchard.Layouts.Providers {
|
||||
// Execute the shape and intercept calls to the Html.SnippetField method.
|
||||
var descriptor = new SnippetDescriptor();
|
||||
shape.DescriptorRegistrationCallback = (Action<SnippetFieldDescriptor>) (fieldDescriptor => {
|
||||
descriptor.Fields.Add(fieldDescriptor);
|
||||
var existingDescriptor = descriptor.Fields.SingleOrDefault(x => x.Name == fieldDescriptor.Name); // Not using Dictionary, as that will break rendering the view for some obscure reason.
|
||||
|
||||
if (existingDescriptor == null)
|
||||
descriptor.Fields.Add(fieldDescriptor);
|
||||
|
||||
if (fieldDescriptor.DisplayName == null)
|
||||
fieldDescriptor.DisplayName = new LocalizedString(fieldDescriptor.Name);
|
||||
|
Loading…
Reference in New Issue
Block a user