|
3 | 3 | | Client Ignia, LLC |
4 | 4 | | Project Topics Library |
5 | 5 | \=============================================================================================================================*/ |
| 6 | +using System; |
6 | 7 | using System.Collections.Generic; |
7 | 8 | using System.Linq; |
8 | 9 | using Microsoft.AspNetCore.Mvc; |
@@ -90,16 +91,45 @@ public IViewComponentResult Invoke( |
90 | 91 | } |
91 | 92 |
|
92 | 93 | /*------------------------------------------------------------------------------------------------------------------------ |
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. |
94 | 100 | \-----------------------------------------------------------------------------------------------------------------------*/ |
95 | 101 | 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 | + } |
97 | 118 |
|
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) { |
100 | 130 | viewModel.TopicList.AddRange( |
101 | 131 | contentTypes |
102 | | - .Where(c => currentContentType.Equals("Container") || c.Attributes.GetBoolean("ImplicitlyPermitted", false)) |
| 132 | + .Where(c => actualContentType.Equals("Container") || c.Attributes.GetBoolean("ImplicitlyPermitted", false)) |
103 | 133 | .Where(c => !c.IsHidden) |
104 | 134 | .OrderBy(c => c.Title) |
105 | 135 | .Select(c => |
|
0 commit comments