-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hidden content type settnigs to allow hidding a content type from…
… GraphQL Schema (#13048)
- Loading branch information
1 parent
6c795ff
commit 86cfabc
Showing
13 changed files
with
114 additions
and
9 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...dules/OrchardCore.ContentTypes/GraphQL/Drivers/GraphQLContentTypeSettingsDisplayDriver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Options; | ||
using OrchardCore.ContentManagement.GraphQL.Options; | ||
using OrchardCore.ContentManagement.GraphQL.Settings; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
using OrchardCore.ContentTypes.Editors; | ||
using OrchardCore.ContentTypes.GraphQL.ViewModels; | ||
using OrchardCore.DisplayManagement.Views; | ||
|
||
namespace OrchardCore.ContentTypes.GraphQL.Drivers; | ||
|
||
public class GraphQLContentTypeSettingsDisplayDriver : ContentTypeDefinitionDisplayDriver | ||
{ | ||
private readonly GraphQLContentOptions _contentOptions; | ||
|
||
public GraphQLContentTypeSettingsDisplayDriver(IOptions<GraphQLContentOptions> optionsAccessor) | ||
{ | ||
_contentOptions = optionsAccessor.Value; | ||
} | ||
|
||
public override IDisplayResult Edit(ContentTypeDefinition contentTypeDefinition) | ||
{ | ||
return Initialize<GraphQLContentTypeSettingsViewModel>("GraphQLContentTypeSettings_Edit", model => | ||
{ | ||
model.Definition = contentTypeDefinition; | ||
model.Settings = contentTypeDefinition.GetSettings<GraphQLContentTypeSettings>(); | ||
model.Options = _contentOptions; | ||
}).Location("Content:5"); | ||
} | ||
|
||
public override async Task<IDisplayResult> UpdateAsync(ContentTypeDefinition contentTypeDefinition, UpdateTypeEditorContext context) | ||
{ | ||
var model = new GraphQLContentTypeSettingsViewModel(); | ||
|
||
await context.Updater.TryUpdateModelAsync(model, Prefix); | ||
|
||
context.Builder.WithSettings(model.Settings); | ||
|
||
return Edit(contentTypeDefinition); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...odules/OrchardCore.ContentTypes/GraphQL/ViewModels/GraphQLContentTypeSettingsViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.AspNetCore.Mvc.ModelBinding; | ||
using OrchardCore.ContentManagement.GraphQL.Options; | ||
using OrchardCore.ContentManagement.GraphQL.Settings; | ||
using OrchardCore.ContentManagement.Metadata.Models; | ||
|
||
namespace OrchardCore.ContentTypes.GraphQL.ViewModels | ||
{ | ||
public class GraphQLContentTypeSettingsViewModel | ||
{ | ||
public GraphQLContentTypeSettings Settings { get; set; } | ||
|
||
[BindNever] | ||
public GraphQLContentOptions Options { get; set; } | ||
|
||
[BindNever] | ||
public ContentTypeDefinition Definition { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...OrchardCore.Modules/OrchardCore.ContentTypes/Views/GraphQLContentTypeSettings.Edit.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@using OrchardCore.ContentTypes.GraphQL.ViewModels | ||
@model GraphQLContentTypeSettingsViewModel | ||
|
||
@{ | ||
var hiddenByDefault = Model.Options.IsHiddenByDefault(Model.Definition.Name); | ||
var hidden = hiddenByDefault ? true : Model.Settings.Hidden; | ||
} | ||
|
||
<div class="mb-3"> | ||
<div class="form-check"> | ||
<input type="checkbox" class="form-check-input" asp-for="Settings.Hidden" checked="@hidden" asp-is-disabled="@hiddenByDefault" /> | ||
<label class="form-check-label" asp-for="Settings.Hidden">@T["Hide"]</label> | ||
@if (hiddenByDefault) | ||
{ | ||
<span class="hint">@T["Setting is hidden by default, and cannot be overwritten."]</span> | ||
} | ||
else | ||
{ | ||
<span class="hint">@T["Check to hide type from the GraphQL schema."]</span> | ||
} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Settings/GraphQLContentTypeSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace OrchardCore.ContentManagement.GraphQL.Settings; | ||
|
||
public class GraphQLContentTypeSettings | ||
{ | ||
public bool Hidden { get; set; } | ||
} |