mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Added support for reusing the same field in a single snippet file.
This commit is contained in:
@@ -8,7 +8,7 @@ using Orchard.Localization;
|
|||||||
namespace Orchard.Layouts.Helpers {
|
namespace Orchard.Layouts.Helpers {
|
||||||
public static class SnippetHtmlExtensions {
|
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;
|
var shape = (dynamic) htmlHelper.ViewData.Model;
|
||||||
|
|
||||||
return new SnippetFieldDescriptorBuilder(shape)
|
return new SnippetFieldDescriptorBuilder(shape)
|
||||||
|
@@ -141,7 +141,10 @@ namespace Orchard.Layouts.Providers {
|
|||||||
// Execute the shape and intercept calls to the Html.SnippetField method.
|
// Execute the shape and intercept calls to the Html.SnippetField method.
|
||||||
var descriptor = new SnippetDescriptor();
|
var descriptor = new SnippetDescriptor();
|
||||||
shape.DescriptorRegistrationCallback = (Action<SnippetFieldDescriptor>) (fieldDescriptor => {
|
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)
|
if (fieldDescriptor.DisplayName == null)
|
||||||
fieldDescriptor.DisplayName = new LocalizedString(fieldDescriptor.Name);
|
fieldDescriptor.DisplayName = new LocalizedString(fieldDescriptor.Name);
|
||||||
|
Reference in New Issue
Block a user