Skip to content

Commit 9beeb8a

Browse files
committed
Fall back to content types of parents
The `ContentTypeListViewComponent` displays a list of content types available to be created under the current topic. It bases this list on the current topic's content type. This is confusing when creating a new topic, however, since the current topic hasn't yet been saved. If the user were to quit creating the current topic, and instead choose a new topic of a different content type, it would be operating against the parent context. As such, if the `actualTopic` can't be found—because it's a new topic!—it should fall back to the parent topic instead. This additionally fixes a bug when creating a `Container`, since in this scenario it adopts the `PermittedContentTypes` from the current topic, instead of from the `ContentTypeDescriptor`, thus allowing the same `Container` class to target collections of different content types. This previously resulted in a null reference exception, however, since `actualTopic` was `null` in this scenario.
1 parent b6868cf commit 9beeb8a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

OnTopic.Editor.AspNetCore/Components/ContentTypeListViewComponent.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ public IViewComponentResult Invoke(
100100
| Get content type
101101
>-------------------------------------------------------------------------------------------------------------------------
102102
| If the database is uninitialized, the content type won't be found. In that case, return an empty view, which will
103-
| effectively hide the component.
103+
| effectively hide the component. If the topic cannot be found, assume it is a new topic and attempt to load the parent
104+
| for context.
104105
\-----------------------------------------------------------------------------------------------------------------------*/
105106
var contentTypes = _topicRepository.GetContentTypeDescriptors();
106-
var actualTopic = _topicRepository.Load(currentTopic.Id);
107+
var actualTopic = _topicRepository.Load(currentTopic.Id)?? _topicRepository.Load(currentTopic.Parent.Id);
107108
var actualContentType = contentTypes.GetTopic(currentTopic.ContentType);
108109

109-
if (actualContentType is null) {
110+
if (actualContentType is null || actualTopic is null) {
110111
return View(viewModel);
111112
}
112113

0 commit comments

Comments
 (0)