Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit e843dfe

Browse files
committed
enable route hijacking, and changing the default surfacecontroller
1 parent 0b75489 commit e843dfe

File tree

6 files changed

+90
-77
lines changed

6 files changed

+90
-77
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Our.Umbraco.DocTypeGridEditor.Web.Controllers;
2+
using System;
3+
using Umbraco.Core;
4+
5+
namespace Our.Umbraco.DocTypeGridEditor.Composing
6+
{
7+
public class Current
8+
{
9+
10+
private static Type _defaultDocTypeGridEditorSurfaceControllerType;
11+
12+
// internal - can only be accessed through Composition at compose time
13+
internal static Type DefaultDocTypeGridEditorSurfaceControllerType
14+
{
15+
get => _defaultDocTypeGridEditorSurfaceControllerType;
16+
set
17+
{
18+
if (value.IsOfGenericType(typeof(DocTypeGridEditorSurfaceController<>)) == false)
19+
throw new InvalidOperationException($"The Type specified ({value}) is not of type {typeof(DocTypeGridEditorSurfaceController<>)}");
20+
_defaultDocTypeGridEditorSurfaceControllerType = value;
21+
}
22+
}
23+
}
24+
}

src/Our.Umbraco.DocTypeGridEditor/Our.Umbraco.DocTypeGridEditor.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@
217217
</ItemGroup>
218218
<ItemGroup>
219219
<Compile Include="Bootstrap.cs" />
220+
<Compile Include="Composing\Current.cs" />
220221
<Compile Include="Extensions\JsonExtensions.cs" />
221222
<Compile Include="Helpers\DocTypeGridEditorHelper.cs" />
222223
<Compile Include="Helpers\XmlHelper.cs" />
@@ -232,11 +233,11 @@
232233
<Compile Include="Extensions\ContentTypeServiceExtensions.cs" />
233234
<Compile Include="Web\Controllers\DocTypeGridEditorSurfaceController.cs" />
234235
<Compile Include="Web\Extensions\HtmlHelperExtensions.cs" />
236+
<Compile Include="Web\Extensions\WebCompositionExtensions.cs" />
235237
<Compile Include="Web\Helpers\SurfaceControllerHelper.cs" />
236238
<Compile Include="Web\Helpers\ViewHelper.cs" />
237239
<Compile Include="Web\Models\PreviewData.cs" />
238240
<Compile Include="Web\Models\PreviewModel.cs" />
239-
<Compile Include="Web\Mvc\DefaultDocTypeGridEditorSurfaceControllerResolver.cs" />
240241
</ItemGroup>
241242
<ItemGroup>
242243
<None Include="app.config" />
@@ -258,7 +259,9 @@
258259
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Views\doctypegrideditor.dialog.html" />
259260
<Content Include="Web\UI\App_Plugins\DocTypeGridEditor\Views\doctypegrideditor.html" />
260261
</ItemGroup>
261-
<ItemGroup />
262+
<ItemGroup>
263+
<Folder Include="Web\Mvc\" />
264+
</ItemGroup>
262265
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
263266
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
264267
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">

src/Our.Umbraco.DocTypeGridEditor/Web/Controllers/DocTypeGridEditorSurfaceController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Our.Umbraco.DocTypeGridEditor.Web.Controllers
99
{
1010
public abstract class DocTypeGridEditorSurfaceController
11-
: DocTypeGridEditorSurfaceController<IPublishedContent>
11+
: DocTypeGridEditorSurfaceController<IPublishedElement>
1212
{ }
1313

1414
public abstract class DocTypeGridEditorSurfaceController<TModel> : SurfaceController

src/Our.Umbraco.DocTypeGridEditor/Web/Extensions/HtmlHelperExtensions.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Web;
22
using System.Web.Mvc;
33
using System.Web.Mvc.Html;
4+
using Our.Umbraco.DocTypeGridEditor.Composing;
45
using Our.Umbraco.DocTypeGridEditor.Web.Helpers;
56
using Umbraco.Core;
67
using Umbraco.Core.Models.PublishedContent;
@@ -48,28 +49,27 @@ public static HtmlString RenderDocTypeGridEditorItem(
4849
return helper.Action(content.ContentType.Alias, controllerName, routeValues);
4950
}
5051

51-
// TODO: FIXME!
5252
//// See if a default surface controller has been registered
53-
//var defaultController = DefaultDocTypeGridEditorSurfaceControllerResolver.Current.GetDefaultControllerType();
54-
//if (defaultController != null)
55-
//{
56-
// var defaultControllerName = defaultController.Name.Substring(0, defaultController.Name.LastIndexOf("Controller"));
57-
58-
// // Try looking for an action named after the editor alias
59-
// if (string.IsNullOrWhiteSpace(editorAlias) == false && SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, editorAlias, true))
60-
// {
61-
// return helper.Action(editorAlias, defaultControllerName, routeValues);
62-
// }
63-
64-
// // Try looking for a doc type alias action
65-
// if (SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, content.DocumentTypeAlias, true))
66-
// {
67-
// return helper.Action(content.DocumentTypeAlias, defaultControllerName, routeValues);
68-
// }
69-
70-
// // Just go with a default action name
71-
// return helper.Action("Index", defaultControllerName, routeValues);
72-
//}
53+
var defaultController = Current.DefaultDocTypeGridEditorSurfaceControllerType;
54+
if (defaultController != null)
55+
{
56+
var defaultControllerName = defaultController.Name.Substring(0, defaultController.Name.LastIndexOf("Controller"));
57+
58+
// Try looking for an action named after the editor alias
59+
if (string.IsNullOrWhiteSpace(editorAlias) == false && SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, editorAlias, true))
60+
{
61+
return helper.Action(editorAlias, defaultControllerName, routeValues);
62+
}
63+
64+
// Try looking for a doc type alias action
65+
if (SurfaceControllerHelper.SurfaceControllerExists(defaultControllerName, content.ContentType.Alias, true))
66+
{
67+
return helper.Action(content.ContentType.Alias, defaultControllerName, routeValues);
68+
}
69+
70+
// Just go with a default action name
71+
return helper.Action("Index", defaultControllerName, routeValues);
72+
}
7373

7474
// Check for preview view
7575
if (string.IsNullOrWhiteSpace(previewViewPath) == false && isPreview)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Umbraco.Core.Composing;
7+
using DtgeCurrent = Our.Umbraco.DocTypeGridEditor.Composing.Current;
8+
9+
namespace Our.Umbraco.DocTypeGridEditor.Web.Extensions
10+
{
11+
public static class WebCompositionExtensions
12+
{
13+
14+
/// <summary>
15+
/// Sets the default controller for rendering DTGE views.
16+
/// </summary>
17+
/// <typeparam name="TController">The type of the controller.</typeparam>
18+
/// <param name="composition">The composition.</param>
19+
/// <remarks>The controller type is registered to the container by the composition.</remarks>
20+
public static void SetDefaultDocTypeGridEditorSurfaceController<TController>(this Composition composition)
21+
=> composition.SetDefaultDocTypeGridEditorSurfaceController(typeof(TController));
22+
23+
/// <summary>
24+
/// Sets the default controller for rendering template views.
25+
/// </summary>
26+
/// <param name="composition">The composition.</param>
27+
/// <param name="controllerType">The type of the controller.</param>
28+
/// <remarks>The controller type is registered to the container by the composition.</remarks>
29+
public static void SetDefaultDocTypeGridEditorSurfaceController(this Composition composition, Type controllerType)
30+
{
31+
composition.OnCreatingFactory["Our.Umbraco.DocTypeGridEditor.Web.DefaultDocTypeGridEditorSurfaceController"] = () =>
32+
{
33+
// no need to register: all IRenderMvcController are registered
34+
//composition.Register(controllerType, Lifetime.Request);
35+
DtgeCurrent.DefaultDocTypeGridEditorSurfaceControllerType = controllerType;
36+
};
37+
}
38+
}
39+
}

src/Our.Umbraco.DocTypeGridEditor/Web/Mvc/DefaultDocTypeGridEditorSurfaceControllerResolver.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)