Skip to content

Commit 12e2126

Browse files
committed
Allow permitted content types to be defined on Category topics
Traditionally, the types of topics that can be created underneath another topic are defined on a topic's content type, via the _Permitted Content Types_ (`ContentTypes`) attribute. For containers, however, it's useful to define this on the topic itself. This way, when we setup a container for organizational purposes, we can specify what type of content types are to be created under that _instance_—as opposed to creating an e.g. `FormContainer` to limit child topics to the `Form` content type. This obviously doesn't provide any real security, but the goal is to fine-tune the user experience so editors don't need to pick through a list for the one type expected, nor do fairly specific types (such as `Form`) need to be set to _implicitly permitted_, thus displaying them well beyond their natural boundaries.
1 parent 6d26698 commit 12e2126

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

OnTopic.Editor.AspNetCore/Components/ContentTypeListViewComponent.cs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
| Client Ignia, LLC
44
| Project Topics Library
55
\=============================================================================================================================*/
6+
using System;
67
using System.Collections.Generic;
78
using System.Linq;
89
using Microsoft.AspNetCore.Mvc;
@@ -90,16 +91,45 @@ public IViewComponentResult Invoke(
9091
}
9192

9293
/*------------------------------------------------------------------------------------------------------------------------
93-
| Get implicit values
94+
| Get permitted content types for container
95+
>-------------------------------------------------------------------------------------------------------------------------
96+
| Containers provide special rules allowing the permitted content types to be defined—or even expanded—on the topic
97+
| instance itself, instead of exclusively on the content type descriptor. This is useful since often containers are meant
98+
| to organize a specific type of content. For example, a Container called "Forms" might be used exclusively to organized
99+
| Form topics.
94100
\-----------------------------------------------------------------------------------------------------------------------*/
95101
var contentTypes = _topicRepository.GetContentTypeDescriptors();
96-
var currentContentType = contentTypes.GetTopic(currentTopic.ContentType);
102+
var actualTopic = _topicRepository.Load(currentTopic.Id);
103+
var actualContentType = contentTypes.GetTopic(currentTopic.ContentType);
104+
105+
if (actualContentType.Key.Equals("Container", StringComparison.InvariantCultureIgnoreCase)) {
106+
viewModel.TopicList.AddRange(
107+
actualTopic
108+
.Relationships
109+
.GetTopics("ContentTypes")
110+
.Select(c =>
111+
new SelectListItem {
112+
Value = getValue(c.Key),
113+
Text = c.Title
114+
}
115+
)
116+
);
117+
}
97118

98-
//If no permitted content types are explicitly set, then implicitly
99-
if (viewModel.TopicList.Count.Equals(1) && !currentContentType.DisableChildTopics) {
119+
/*------------------------------------------------------------------------------------------------------------------------
120+
| Get implicit values
121+
>-------------------------------------------------------------------------------------------------------------------------
122+
| If no permitted content types are explicitly defined on the content type—or the topic, in the case of a container—then
123+
| we instead load a generic list of content types. We don't want to display all content types, however, as many make
124+
| little sense outside of specific contexts. For instance, most content types that derive from Items only make sense as
125+
| nested topics. Similarly, specialized types like Home might only make sense in one location. To facilitate this, only
126+
| content types explicitly annotated as "implicitly permitted", and which are not marked as hidden are displayed. This
127+
| typically include the Page content type, and popular derivatives of it, such as Content List.
128+
\-----------------------------------------------------------------------------------------------------------------------*/
129+
if (viewModel.TopicList.Count.Equals(1) && !actualContentType.DisableChildTopics) {
100130
viewModel.TopicList.AddRange(
101131
contentTypes
102-
.Where(c => currentContentType.Equals("Container") || c.Attributes.GetBoolean("ImplicitlyPermitted", false))
132+
.Where(c => actualContentType.Equals("Container") || c.Attributes.GetBoolean("ImplicitlyPermitted", false))
103133
.Where(c => !c.IsHidden)
104134
.OrderBy(c => c.Title)
105135
.Select(c =>

0 commit comments

Comments
 (0)