Skip to content

Commit 54cbcef

Browse files
Category code review updates
1 parent 3a2ffcd commit 54cbcef

4 files changed

Lines changed: 56 additions & 45 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,5 @@ __pycache__/
267267
# Cake - Uncomment if you are using it
268268
# tools/
269269

270-
App_Data/
270+
App_Data/
271+
/docs/superpowers

src/Geta.Optimizely.Categories/DataAnnotations/CategoriesAttribute.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
76
using EPiServer.ServiceLocation;
87
using EPiServer.Shell;
98
using EPiServer.Shell.ObjectEditing;
9+
using Geta.Optimizely.Categories.EditorDescriptors;
1010
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
1111

1212
namespace Geta.Optimizely.Categories.DataAnnotations
@@ -32,25 +32,8 @@ public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
3232
if (context.DisplayMetadata.AdditionalValues[ExtendedMetadata.ExtendedMetadataDisplayKey] is not ExtendedMetadata additionalValue)
3333
return;
3434

35-
var allowedTypes = new[] { typeof(CategoryData) };
36-
var categoryRepositoryDescriptor = _contentRepositoryDescriptors.First(x => x.Key == CategoryContentRepositoryDescriptor.RepositoryKey);
37-
// For a packaged module the editor JS must be addressed via its served URL
38-
// (module client-resource path + version). Paths.ToClientResource keeps the
39-
// version automatic.
40-
additionalValue.ClientEditingClass = Paths.ToClientResource(Constants.ModuleName, "ClientResources/Scripts/editors/CategorySelector.js");
41-
additionalValue.EditorConfiguration["AllowedTypes"] = allowedTypes;
42-
additionalValue.EditorConfiguration["AllowedDndTypes"] = allowedTypes;
43-
additionalValue.OverlayConfiguration["AllowedDndTypes"] = allowedTypes;
44-
additionalValue.EditorConfiguration["categorySettings"] = _categorySettings;
45-
additionalValue.EditorConfiguration["repositoryKey"] = CategoryContentRepositoryDescriptor.RepositoryKey;
46-
additionalValue.EditorConfiguration["settings"] = categoryRepositoryDescriptor;
47-
additionalValue.EditorConfiguration["roots"] = categoryRepositoryDescriptor.Roots;
48-
additionalValue.EditorConfiguration["multiple"] = true;
49-
50-
// CMS 13: opt the [Categories] attribute path into the native ES6 module editor pipeline,
51-
// matching CategoriesEditorDescriptor. Without this flag, CMS would treat ClientEditingClass
52-
// as a legacy Dojo module id.
53-
additionalValue.EditorConfiguration["isJavascriptModule"] = true;
35+
// Shared with CategoriesEditorDescriptor (the UIHint path) — both wire the same editor.
36+
CategoryEditorMetadata.Apply(additionalValue, _contentRepositoryDescriptors, _categorySettings);
5437
}
5538
}
5639
}

src/Geta.Optimizely.Categories/EditorDescriptors/CategoriesEditorDescriptor.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Linq;
76
using EPiServer.Core;
87
using EPiServer.Shell;
98
using EPiServer.Shell.ObjectEditing;
@@ -39,29 +38,8 @@ public CategoriesEditorDescriptor(
3938

4039
public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
4140
{
42-
var allowedTypes = new[] { typeof(CategoryData) };
43-
var categoryRepositoryDescriptor = _contentRepositoryDescriptors
44-
.First(x => x.Key == CategoryContentRepositoryDescriptor.RepositoryKey);
45-
46-
// For a packaged module the editor JS must be addressed via its served URL
47-
// (module client-resource path + version). Paths.ToClientResource keeps the
48-
// version automatic, so this still works after the package version is bumped.
49-
metadata.ClientEditingClass = Paths.ToClientResource(
50-
Constants.ModuleName,
51-
"ClientResources/Scripts/editors/CategorySelector.js");
52-
53-
metadata.EditorConfiguration["AllowedTypes"] = allowedTypes;
54-
metadata.EditorConfiguration["AllowedDndTypes"] = allowedTypes;
55-
metadata.OverlayConfiguration["AllowedDndTypes"] = allowedTypes;
56-
metadata.EditorConfiguration["categorySettings"] = _categorySettings;
57-
metadata.EditorConfiguration["repositoryKey"] = CategoryContentRepositoryDescriptor.RepositoryKey;
58-
metadata.EditorConfiguration["settings"] = categoryRepositoryDescriptor;
59-
metadata.EditorConfiguration["roots"] = categoryRepositoryDescriptor.Roots;
60-
metadata.EditorConfiguration["multiple"] = true;
61-
62-
// CMS 13: opt into the native ES6 module editor pipeline. Without this flag,
63-
// CMS would treat ClientEditingClass as a legacy Dojo module id.
64-
metadata.EditorConfiguration["isJavascriptModule"] = true;
41+
// Shared with CategoriesAttribute (the [Categories] path) — both wire the same editor.
42+
CategoryEditorMetadata.Apply(metadata, _contentRepositoryDescriptors, _categorySettings);
6543

6644
// Intentionally no `base.ModifyMetadata` call — see class summary.
6745
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Geta Digital. All rights reserved.
2+
// Licensed under Apache-2.0. See the LICENSE file in the project root for more information
3+
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using EPiServer.Shell;
7+
using EPiServer.Shell.ObjectEditing;
8+
9+
namespace Geta.Optimizely.Categories.EditorDescriptors
10+
{
11+
/// <summary>
12+
/// Shared metadata setup for the CMS 13 ES6 module category-picker editor. Both
13+
/// <see cref="DataAnnotations.CategoriesAttribute"/> (the <c>[Categories]</c> path) and
14+
/// <see cref="CategoriesEditorDescriptor"/> (the <c>UIHint = "Categories"</c> path) wire the
15+
/// exact same editor onto a property, so the configuration lives here to avoid drift.
16+
/// </summary>
17+
internal static class CategoryEditorMetadata
18+
{
19+
public static void Apply(
20+
ExtendedMetadata metadata,
21+
IEnumerable<IContentRepositoryDescriptor> contentRepositoryDescriptors,
22+
CategorySettings categorySettings)
23+
{
24+
var allowedTypes = new[] { typeof(CategoryData) };
25+
var categoryRepositoryDescriptor = contentRepositoryDescriptors
26+
.First(x => x.Key == CategoryContentRepositoryDescriptor.RepositoryKey);
27+
28+
// For a packaged module the editor JS must be addressed via its served URL
29+
// (module client-resource path + version). Paths.ToClientResource keeps the
30+
// version automatic, so this still works after the package version is bumped.
31+
metadata.ClientEditingClass = Paths.ToClientResource(
32+
Constants.ModuleName,
33+
"ClientResources/Scripts/editors/CategorySelector.js");
34+
35+
metadata.EditorConfiguration["AllowedTypes"] = allowedTypes;
36+
metadata.EditorConfiguration["AllowedDndTypes"] = allowedTypes;
37+
metadata.OverlayConfiguration["AllowedDndTypes"] = allowedTypes;
38+
metadata.EditorConfiguration["categorySettings"] = categorySettings;
39+
metadata.EditorConfiguration["repositoryKey"] = CategoryContentRepositoryDescriptor.RepositoryKey;
40+
metadata.EditorConfiguration["settings"] = categoryRepositoryDescriptor;
41+
metadata.EditorConfiguration["roots"] = categoryRepositoryDescriptor.Roots;
42+
metadata.EditorConfiguration["multiple"] = true;
43+
44+
// CMS 13: opt into the native ES6 module editor pipeline. Without this flag,
45+
// CMS would treat ClientEditingClass as a legacy Dojo module id.
46+
metadata.EditorConfiguration["isJavascriptModule"] = true;
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)