orchard の Menu 部分を拡張する最良の方法は何ですか?
ほとんどのコンテンツ タイプで通常のメニュー パーツを使用したいと考えています。
しかし、カスタム MainNavigationMenuPart も必要です。これには、メニュー パーツにあるすべてのものがありますが、メディア ピッカー フィールドとテキスト フィールドが追加されます。- メニューのロールオーバーで表示されるこれらのアイテム。
オプション1
私はこれが最善の方法だと思います...
カスタム メニュー パーツの作成を検討しましたが、メニュー パーツが現在どのように機能しているかについて多くの機能があるように見えますが、DRY の方法でこれを利用する最善の方法がわかりません。
MenuPartItem を customPart に追加できるので、メイン メニュー パーツ モデルは次のようになります。
public class MainMenuPart : ContentPart<MainMenuRecord>
{
public MenuPart MenuPart { get; set; }
public string ShortDescription
{
get { return Record.ShortDescription; }
set { Record.ShortDescription = value; }
}
}
しかし ...
- パーツのエディター ビューでこれをレンダリングするにはどうすればよいですか?
- 既存の MenuPartItemEditor を使用したい。
- この情報を部品のレコードに保存するにはどうすればよいですか?
オプション 2
メニュー部分に(cms経由で)フィールドを追加することも検討しました。
私のメニュー部分は今、バックエンドでこのように見えます
ここでは、コンテンツ タイプに応じて、メニューの管理ビューをカスタマイズしています。Views/EditorTemplatesでParts.Navigation.Menu.Edit.cshtmlを作成することを購入します。私のカスタムでは、メニュー パーツにアクセスできますが、パーツに追加したフィールドの表示を制御できるようです。(メニュー画像、ハイライト、簡単な説明)
これがカスタム Parts.Navigation.Menu.Edit.cshtml です (オリジナルは Orchard.Core/Navigation/Views/EditorTemplates/Parts.Navigation.Menu.Edit.cshtml にあります)。
@model Orchard.Core.Navigation.ViewModels.MenuPartViewModel
@using Orchard.ContentManagement
@using Orchard.Core.Navigation.Models;
@if (!Model.ContentItem.TypeDefinition.Settings.ContainsKey("Stereotype") || Model.ContentItem.TypeDefinition.Settings["Stereotype"] != "MenuItem")
{
if (Model.ContentItem.ContentType == "StandardIndexPage" ||
Model.ContentItem.ContentType == "AlternateIndexPage" ||
Model.ContentItem.ContentType == "MapIndexPage")
{
var sd = ((dynamic)Model.ContentItem).MenuPart.ShortDescription;
@sd
<fieldset>
@Html.HiddenFor(m => m.OnMenu, true)
@Html.HiddenFor(m => m.CurrentMenuId, Model.CurrentMenuId)
<div>
<label for="MenuText">@T("Menu text (will appear on main menu)")</label>
@Html.TextBoxFor(m => m.MenuText, new { @class = "text-box single-line" })
<span class="hint">@T("The text that should appear in the menu.")</span>
</div>
</fieldset>
}
else
{
<fieldset>
@Html.EditorFor(m => m.OnMenu)
<label for="@Html.FieldIdFor(m => m.OnMenu)" class="forcheckbox">@T("Show on menu")</label>
<div data-controllerid="@Html.FieldIdFor(m => m.OnMenu)" class="">
<select id="@Html.FieldIdFor(m => m.CurrentMenuId)" name="@Html.FieldNameFor(m => m.CurrentMenuId)">
@foreach (ContentItem menu in Model.Menus)
{
@Html.SelectOption(Model.CurrentMenuId, menu.Id, Html.ItemDisplayText(menu).ToString())
}
</select>
<span class="hint">@T("Select which menu you want the content item to be displayed on.")</span>
<label for="MenuText">@T("Menu text")</label>
@Html.TextBoxFor(m => m.MenuText, new { @class = "text-box single-line" })
<span class="hint">@T("The text that should appear in the menu.")</span>
</div>
</fieldset>
}
}
else
{
<fieldset>
<label for="MenuText">@T("Menu text")</label>
@Html.TextBoxFor(m => m.MenuText, new { @class = "textMedium", autofocus = "autofocus" })
<span class="hint">@T("The text that should appear in the menu.")</span>
@Html.HiddenFor(m => m.OnMenu, true)
@Html.HiddenFor(m => m.CurrentMenuId, Request["menuId"])
</fieldset>
}
また、テーマのplacement.infoを使用してフィールドの表示を制御しようとしました
<Match ContentType="StandardIndexPage">
<Place Fields_Boolean_Edit-Highlight="-"/>
</Match>
成功しませんでした。