mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
#18180: Adding a technical name to Widgets
Work Item: 18180 --HG-- branch : 1.x
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
ec573e5476f7e8a5a61593d6393e9985e9484fcc src/Orchard.Web/Modules/Orchard.Forms
|
||||
e89c4fadfb710e2f733b74665b0c176829f6b992 src/Orchard.Web/Modules/Orchard.Projections
|
||||
431490c4617992f03bcd1c150828a0ea35934d23 src/Orchard.Web/Modules/Orchard.Projections
|
||||
01b83c05050bb731d9f69256bbe8884d458ea1c9 src/Orchard.Web/Modules/Orchard.Rules
|
||||
65057c6a5cd71f7994ba9bcbeece50dbb737620e src/Orchard.Web/Modules/Orchard.TaskLease
|
||||
c2e3c396c1fc6c60b131bfc9f83564c6f8d18e58 src/Orchard.Web/Modules/Orchard.Tokens
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.Widgets.Models;
|
||||
using Orchard.Widgets.Services;
|
||||
|
||||
@@ -10,11 +12,17 @@ namespace Orchard.Widgets.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class WidgetPartDriver : ContentPartDriver<WidgetPart> {
|
||||
private readonly IWidgetsService _widgetsService;
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public WidgetPartDriver(IWidgetsService widgetsService) {
|
||||
public WidgetPartDriver(IWidgetsService widgetsService, IContentManager contentManager) {
|
||||
_widgetsService = widgetsService;
|
||||
_contentManager = contentManager;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override DriverResult Editor(WidgetPart widgetPart, dynamic shapeHelper) {
|
||||
widgetPart.AvailableZones = _widgetsService.GetZones();
|
||||
widgetPart.AvailableLayers = _widgetsService.GetLayers();
|
||||
@@ -34,6 +42,20 @@ namespace Orchard.Widgets.Drivers {
|
||||
protected override DriverResult Editor(WidgetPart widgetPart, IUpdateModel updater, dynamic shapeHelper) {
|
||||
updater.TryUpdateModel(widgetPart, Prefix, null, null);
|
||||
|
||||
if(string.IsNullOrWhiteSpace(widgetPart.Title)) {
|
||||
updater.AddModelError("Title", T("Title can't be empty."));
|
||||
}
|
||||
|
||||
// if there is a name, ensure it's unique
|
||||
if(!string.IsNullOrWhiteSpace(widgetPart.Name)) {
|
||||
widgetPart.Name = widgetPart.Name.ToSafeName();
|
||||
|
||||
var widgets = _contentManager.Query<WidgetPart, WidgetPartRecord>().Where(x => x.Name == widgetPart.Name && x.Id != widgetPart.Id).Count();
|
||||
if(widgets > 0) {
|
||||
updater.AddModelError("Name", T("A Widget with the same Name already exists."));
|
||||
}
|
||||
}
|
||||
|
||||
_widgetsService.MakeRoomForWidgetPosition(widgetPart);
|
||||
|
||||
return Editor(widgetPart, shapeHelper);
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Orchard.Widgets.Handlers {
|
||||
public class WidgetPartHandler : ContentHandler {
|
||||
public WidgetPartHandler(IRepository<WidgetPartRecord> widgetsRepository) {
|
||||
Filters.Add(StorageFilter.For(widgetsRepository));
|
||||
|
||||
OnInitializing<WidgetPart>((context, part) => part.RenderTitle = true);
|
||||
}
|
||||
|
||||
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
|
||||
|
||||
@@ -43,6 +43,8 @@ namespace Orchard.Widgets {
|
||||
.Column<string>("Title")
|
||||
.Column<string>("Position")
|
||||
.Column<string>("Zone")
|
||||
.Column<bool>("RenderTitle", c => c.WithDefault(true))
|
||||
.Column<string>("Name")
|
||||
);
|
||||
|
||||
ContentDefinitionManager.AlterTypeDefinition("Layer",
|
||||
@@ -60,7 +62,7 @@ namespace Orchard.Widgets {
|
||||
.WithSetting("Stereotype", "Widget")
|
||||
);
|
||||
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
@@ -68,5 +70,13 @@ namespace Orchard.Widgets {
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom2() {
|
||||
SchemaBuilder
|
||||
.AlterTable("WidgetPartRecord", table => table.AddColumn<bool>("RenderTitle", c => c.WithDefault(true)))
|
||||
.AlterTable("WidgetPartRecord", table => table.AddColumn<string>("Name"));
|
||||
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,14 @@ namespace Orchard.Widgets.Models {
|
||||
set { Record.Zone = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the Title should be rendered on the front-end
|
||||
/// </summary>
|
||||
public bool RenderTitle {
|
||||
get { return Record.RenderTitle; }
|
||||
set { Record.RenderTitle = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The widget's position within the zone.
|
||||
/// </summary>
|
||||
@@ -34,6 +42,14 @@ namespace Orchard.Widgets.Models {
|
||||
set { Record.Position = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The technical name of the widget.
|
||||
/// </summary>
|
||||
public string Name {
|
||||
get { return Record.Name; }
|
||||
set { Record.Name = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The layerPart where the widget belongs.
|
||||
/// </summary>
|
||||
|
||||
@@ -5,5 +5,7 @@ namespace Orchard.Widgets.Models {
|
||||
public virtual string Title { get; set; }
|
||||
public virtual string Position { get; set; }
|
||||
public virtual string Zone { get; set; }
|
||||
public virtual bool RenderTitle { get; set; }
|
||||
public virtual string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.Utility.Extensions;
|
||||
using Orchard.Widgets.Models;
|
||||
@@ -22,15 +23,25 @@ namespace Orchard.Widgets {
|
||||
|
||||
ContentItem contentItem = displaying.Shape.ContentItem;
|
||||
if (contentItem != null) {
|
||||
var widgetPart = contentItem.As<WidgetPart>();
|
||||
widget.Classes.Add("widget-" + contentItem.ContentType.HtmlClassify());
|
||||
|
||||
var zoneName = contentItem.As<WidgetPart>().Zone;
|
||||
|
||||
var zoneName = widgetPart.Zone;
|
||||
|
||||
// Widget__[ZoneName] e.g. Widget-SideBar
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + zoneName);
|
||||
|
||||
// Widget__[ContentType] e.g. Widget-BlogArchive
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__" + contentItem.ContentType);
|
||||
|
||||
// using the technical name to add a CSS class and an alternate
|
||||
if (!String.IsNullOrWhiteSpace(widgetPart.Name)) {
|
||||
widget.Classes.Add("widget-" + widgetPart.Name);
|
||||
|
||||
// Widget__Name_[Name]
|
||||
displaying.ShapeMetadata.Alternates.Add("Widget__Name_" + widgetPart.Name);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,16 +2,27 @@
|
||||
<fieldset>
|
||||
@Html.LabelFor(widget => widget.Zone, T("Zone"))
|
||||
@Html.DropDownListFor(widget => widget.Zone, new SelectList(Model.AvailableZones))
|
||||
<span class="hint">@T("The Zone in the Layout where the Widget will be rendered.")</span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(widget => widget.LayerId, T("Layer"))
|
||||
@Html.DropDownListFor(widget => widget.LayerId, new SelectList(Model.AvailableLayers, "Id", "Name"))
|
||||
<span class="hint">@T("The Layer where the Widget when be rendered.")</span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(widget => widget.Position, T("Position"))
|
||||
@Html.TextBoxFor(widget => widget.Position, new { @class = "text text-small"})
|
||||
<span class="hint">@T("The position of the Widget inside the Zone.")</span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(widget => widget.Title, T("Title"))
|
||||
@Html.EditorFor(widget => widget.Title)
|
||||
</fieldset>
|
||||
@Html.TextBoxFor(widget => widget.Title, new { @class = "textMedium" })
|
||||
<span class="hint">@T("The title of the Widget.")</span>
|
||||
@Html.EditorFor(widget => widget.RenderTitle)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.RenderTitle)">@T("Check to to render the title on the front-end, uncheck to hide")</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
@Html.LabelFor(widget => widget.Name, T("Name"))
|
||||
@Html.TextBoxFor(widget => widget.Name)
|
||||
<span class="hint">@T("The technical name of the Widget, used for css class and alternates.")</span>
|
||||
</fieldset>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
@using Orchard.ContentManagement;
|
||||
@using Orchard.Widgets.Models;
|
||||
@{
|
||||
var title = ((IContent)Model.ContentItem).As<WidgetPart>().Title;
|
||||
var widgetPart = ((IContent)Model.ContentItem).As<WidgetPart>();
|
||||
var tag = Tag(Model, "article");
|
||||
}
|
||||
@tag.StartElement
|
||||
@if (HasText(title) || Model.Header != null) {
|
||||
@if ( (widgetPart.RenderTitle && HasText(widgetPart.Title)) || Model.Header != null) {
|
||||
<header>
|
||||
@if (HasText(title)) {
|
||||
<h1>@title</h1>
|
||||
@if ((widgetPart.RenderTitle && HasText(widgetPart.Title))) {
|
||||
<h1>@widgetPart.Title</h1>
|
||||
}
|
||||
@Display(Model.Header)
|
||||
</header>
|
||||
|
||||
Reference in New Issue
Block a user