3

新しいパーツ、タイプ、およびカスタム アクティビティを作成するカスタム モジュールを Orchard で構築しましたが、特定の親に関連付けられたすべてのコンテンツ アイテムのコピーを作成する必要がある最後の部分に苦労しています。アイテム。

たとえば、誰かが「トレード ショー」(私のモジュールからの新しいタイプ) を作成すると、クライアントは一度に 1 つのショーを実行するため、そこからさまざまなサブページ (道案内、ベンダー マップなど) を作成できます。私がしなければならないことは、彼らが新しい見本市を作成するときに、最新の以前のショーを取得したいということです (これ_contentManager.HqlQuery().ForType("TradeShow").ForVersion(VersionOptions.Latest).ForVersion(VersionOptions.Published).List().Last()は最も効率的な方法ではありませんが、機能し、レコード数は〜になります10 5 年後)、その古いショーに関連するすべての子ページを見つけて、それらを新しいコンテンツ アイテムにコピーします。古いショーのパーツを参照する必要がある場合があるため、それらはコピーである必要があります。変更される可能性があります。すべての通常の理由。

アクティビティで以前のショーを参照するすべてのコンテンツ アイテムを見つけるにはどうすればよいですか? アクティビティの完全なクラスは次のとおりです。

using System;
using System.Collections.Generic;
using System.Linq;
using Orchard.Autoroute.Services;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Projections.Models;
using Orchard.Projections.Services;
using Orchard.Workflows.Models;
using Orchard.Workflows.Services;
using Orchard.Workflows.Activities;

namespace Orchard.Web.Modules.TradeShows.Activities
{
public class TradeShowPublishedActivity : Task
{
    private readonly IContentManager _contentManager;
    private readonly IAutorouteService _autorouteService;
    private readonly IProjectionManager _projectionManager;

    public TradeShowPublishedActivity(IContentManager contentManager, IAutorouteService autorouteService, IProjectionManager projectionManager)
    {
        _contentManager = contentManager;
        _autorouteService = autorouteService;
        _projectionManager = projectionManager;

        T = NullLocalizer.Instance;
    }

    public Localizer T { get; set; }

    public override LocalizedString Category
    {
        get { return T("Flow"); }
    }

    public override LocalizedString Description
    {
        get { return T("Handles the automatic creation of content pages for the new show."); }
    } 

    public override string Name
    {
        get { return "TradeShowPublished"; }
    }

    public override string Form
    {
        get { return null; }
    }

    public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext)
    {
        yield return T("Done");
    }

    public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
    {
        var priorShow = _contentManager.HqlQuery().ForType("TradeShow").ForVersion(VersionOptions.Latest).ForVersion(VersionOptions.Published).List().Last();
        var tradeShowPart = priorShow.Parts.Where(p => p.PartDefinition.Name == "TradeShowContentPart").Single();

        //new show alias
        //workflowContext.Content.ContentItem.As<Orchard.Autoroute.Models.AutoroutePart>().DisplayAlias

        yield return T("Done");
    }
}

}

私のMigrations.csファイルは、子ページに使用される部分を設定して、次のように親ショーを参照します。

ContentDefinitionManager.AlterPartDefinition("AssociatedTradeShowPart", builder => builder.WithField("Trade Show", cfg => cfg.OfType("ContentPickerField")
                                                                                                                                  .WithDisplayName("Trade Show")
                                                                                                                                  .WithSetting("ContentPickerFieldSettings.Attachable", "true")
                                                                                                                                  .WithSetting("ContentPickerFieldSettings.Description", "Select the trade show this item is for.")
                                                                                                                                  .WithSetting("ContentPickerFieldSettings.Required", "true")
                                                                                                                                  .WithSetting("ContentPickerFieldSettings.DisplayedContentTypes", "TradeShow")
                                                                                                                                  .WithSetting("ContentPickerFieldSettings.Multiple", "false")
                                                                                                                                  .WithSetting("ContentPickerFieldSettings.ShowContentTab", "true")));

次に、私の子ページ (今のところ 1 つだけですが、さらに多くのページが作成されます) は次のように作成されます。

ContentDefinitionManager.AlterTypeDefinition("ShowDirections", cfg => cfg.DisplayedAs("Show Directions")
                                                                                 .WithPart("AutoroutePart", builder => builder.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
                                                                                                                               .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
                                                                                                                               .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Title', Pattern: '{Content.Slug}', Description: 'international-trade-show'}]")
                                                                                                                               .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
                                                                                 .WithPart("CommonPart", builder => builder.WithSetting("DateEditorSettings.ShowDateEditor", "false"))
                                                                                 .WithPart("PublishLaterPart")
                                                                                 .WithPart("TitlePart")
                                                                                 .WithPart("AssociatedTradeShowPart") /* allows linking to parent show */
                                                                                 .WithPart("ContainablePart", builder => builder.WithSetting("ContainablePartSettings.ShowContainerPicker", "true"))
                                                                                 .WithPart("BodyPart"));
4

1 に答える 1