-
Hi Everyone, I'm continuing to explore Orchard Core. This time, I'm working on customizing the Orchard Core I created my own public class TextFieldCustomSettingsDisplayDriver : ContentPartFieldDefinitionDisplayDriver<TextField>
{
public override IDisplayResult Edit(ContentPartFieldDefinition partFieldDefinition)
{
return Initialize<TextFieldCustomSettingsViewModel>("TextFieldCustomSettings_Edit", model =>
{
var settings = partFieldDefinition.GetSettings<TextFieldCustomSettings>();
model.IsNotEditable = settings.IsNotEditable;
})
.Location("Content");
}
public override async Task<IDisplayResult> UpdateAsync(ContentPartFieldDefinition partFieldDefinition, UpdatePartFieldEditorContext context)
{
var viewModel = new TextFieldCustomSettingsViewModel();
if (await context.Updater.TryUpdateModelAsync(viewModel, Prefix))
{
var settings = new TextFieldCustomSettings
{
IsNotEditable = viewModel.IsNotEditable
};
context.Builder.WithSettings(settings);
}
return Edit(partFieldDefinition);
}
} Now, I want to utilize the @model OrchardCore.ContentFields.ViewModels.EditTextFieldViewModel
@using MyModule.ContentFields.Models
@using OrchardCore
@using OrchardCore.ContentFields.Settings
@using OrchardCore.ContentManagement.Metadata.Models
@using OrchardCore.Localization
@using OrchardCore.Mvc.Utilities
@{
var settings = Model.PartFieldDefinition.GetSettings<TextFieldSettings>();
// Access my custom settings
var customSettings = Model.PartFieldDefinition.GetSettings<TextFieldCustomSettings>();
var culture = await Orchard.GetContentCultureAsync(Model.Field.ContentItem);
}
@if (customSettings.IsNotEditable) // Using my custom settings to conditionally render
{
<p> Here my new field not editable.</p>
}
else
{
<div class="@Orchard.GetFieldWrapperClasses(Model.PartFieldDefinition)" id="@Html.IdFor(x => x.Text)_FieldWrapper">
<label asp-for="Text" class="@Orchard.GetLabelClasses()">@Model.PartFieldDefinition.DisplayName()</label>
<div class="@Orchard.GetEndClasses()">
<input asp-for="Text" class="form-control content-preview-text" dir="@culture.GetLanguageDirection()" />
@if (!string.IsNullOrEmpty(settings.Hint))
{
<span class="hint">@settings.Hint</span>
}
</div>
</div>
} Now, I'm a bit confused 🤔 My override for
Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
@douwinga if you have experience with this, please let me know 😊🙏 Thank you |
Beta Was this translation helpful? Give feedback.
-
I found a solution 🥳
🤔 I have one more question:
@model OrchardCore.ContentFields.ViewModels.EditTextFieldViewModel
@using MyModule.ContentFields.Models
@using OrchardCore
@using OrchardCore.ContentFields.Settings
@using OrchardCore.ContentManagement.Metadata.Models
@using OrchardCore.Localization
@using OrchardCore.Mvc.Utilities
@{
var settings = Model.PartFieldDefinition.GetSettings<TextFieldSettings>();
// Access my custom settings
var customSettings = Model.PartFieldDefinition.GetSettings<TextFieldCustomSettings>();
var culture = await Orchard.GetContentCultureAsync(Model.Field.ContentItem);
}
@if (customSettings.IsNotEditable) // Using my custom settings to conditionally render
{
<p> Here is my new field, not editable.</p>
}
else
{
// Use the original TextField.Edit.cshtml instead of duplicating code in this override
await Html.RenderPartialAsync("OrchardCore.ContentFields/Views/TextField.Edit.cshtml", Model);
} Regarding the documentation: @Piedone, about the override of the Admin views, I didn't find any information in the Orchard Core reference. Could it be useful to add this info here on the Thank you |
Beta Was this translation helpful? Give feedback.
-
For your second question under #15644 (comment): You can add your own driver for Overriding shapes like you did is only necessary if you want to fully override a template, not if you want to add to the editor or display of a part/field. |
Beta Was this translation helpful? Give feedback.
I found a solution 🥳
Views/OrchardCore.ContentFields/TextField.Edit.cshtml
path to override it. It's sufficient to put theTextField.Edit.cshtml
in theViews
folder of my module;Manifest.cs
to theOrchardCore.ContentFields
module, which containsTextField.Edit.cshtml
(the page that we want to override):Dependencies = new[] { "OrchardCore.ContentFields" }
.🤔 I have one more question:
TextField.Edit.cshtml
view in theelse
part as I have done in the second example here, can I render the originalTextField.Edit.cshtml
usingRenderPart…