GetMapping() public method

Returns a mapping object
public GetMapping ( string templateId, Database database ) : IMultiVariantMapping
templateId string
database Database
return IMultiVariantMapping
コード例 #1
0
        public void RunInsertPipeline(ClientPipelineArgs args)
        {
            if (!args.IsPostBack)
            {
                Sitecore.Context.ClientPage.ClientResponse.Input("Enter a name for the new variant: ", string.Empty);
                args.WaitForPostBack();
            }
            else
            {
                if (!args.HasResult || args.Result == null)
                {
                    return;
                }

                //verify valid name
                string nameError = ItemUtil.GetItemNameError(args.Result);
                if(!string.IsNullOrEmpty(nameError))
                {
                    SheerResponse.Alert(nameError, new string[0]);
                    return;
                }

                string newItemName = args.Result;
                string currentItemId = args.Parameters["currentid"];

                Item currentItem = Sitecore.Context.ContentDatabase.GetItem(currentItemId);
                if(currentItem.IsNull())
                {
                    return;
                }

                MultiVariantProcessor processor = new MultiVariantProcessor();
                IMultiVariantMapping multiVariantMapping = processor.GetMapping(currentItem.TemplateID.ToString(), Sitecore.Context.ContentDatabase);
                if (multiVariantMapping == null)
                {
                    return;
                }

                //create a new item to be used as variant
                multiVariantMapping.CreateVariantItem(currentItem, newItemName);
            }
        }
コード例 #2
0
        protected void SetContent(ClientPipelineArgs args)
        {
            Predicate<VariableValueItemStub> match = null;
            Predicate<VariableValueItemStub> predicate2 = null;
            ID id;
            string str = args.Parameters["variationid"];
            if (string.IsNullOrEmpty(str))
            {
                SheerResponse.Alert("Item not found.", new string[0]);
            }
            else
            {
                id = ShortID.DecodeID(str);
                if (args.IsPostBack)
                {
                    if (args.HasResult)
                    {
                        List<VariableValueItemStub> variableValues = VariableValues;
                        if (match == null)
                        {
                            match = v => v.Id == id;
                        }
                        VariableValueItemStub stub = variableValues.Find(match);
                        if (stub != null)
                        {
                            stub.Datasource = args.Result;
                            var output = new HtmlTextWriter(new StringWriter());
                            RenderContentControls(output, stub);
                            SheerResponse.SetOuterHtml(str + "_content", output.InnerWriter.ToString());
                            VariableValues = variableValues;
                        }
                    }
                }
                else
                {
                    if (predicate2 == null)
                    {
                        predicate2 = v => v.Id == id;
                    }
                    VariableValueItemStub stub2 = VariableValues.Find(predicate2);
                    if ((stub2 != null) && ((Rendering != null) && !string.IsNullOrEmpty(Rendering.ItemID)))
                    {
                        Item renderingItem = Client.ContentDatabase.GetItem(Rendering.ItemID);
                        if (renderingItem == null)
                        {
                            SheerResponse.Alert("Item not found.", new string[0]);
                        }
                        else
                        {
                            //get current content item
                            Item variantSourceItem = (ContextItemUri == null) ? null : Client.ContentDatabase.GetItem(ContextItemUri.ToDataUri());

                            if (variantSourceItem.IsNotNull())
                            {
                                //use variant mapping functionality to find proper source
                                MultiVariantProcessor processor = new MultiVariantProcessor();
                                IMultiVariantMapping mapping = processor.GetMapping(variantSourceItem.TemplateID.ToString(), Client.ContentDatabase);
                                if(mapping != null)
                                {
                                    //set mapping
                                    variantSourceItem = mapping.VariantSource(variantSourceItem);
                                }
                            }

                            var args3 = new GetRenderingDatasourceArgs(renderingItem);
                            args3.FallbackDatasourceRoots = new List<Item> {variantSourceItem};
                            args3.ContentLanguage = ((variantSourceItem != null) ? variantSourceItem.Language : null);
                            args3.ContextItemPath = (variantSourceItem != null) ? variantSourceItem.Paths.FullPath : string.Empty;
                            args3.ShowDialogIfDatasourceSetOnRenderingItem = true;
                            args3.CurrentDatasource = (string.IsNullOrEmpty(stub2.Datasource) ? Rendering.Datasource : stub2.Datasource);
                            GetRenderingDatasourceArgs args2 = args3;
                            CorePipeline.Run("getRenderingDatasource", args2);
                            if (string.IsNullOrEmpty(args2.DialogUrl))
                            {
                                SheerResponse.Alert("An error ocurred.", new string[0]);
                            }
                            else
                            {
                                SheerResponse.ShowModalDialog(args2.DialogUrl, "460px", "460px", string.Empty, true);
                                args.WaitForPostBack();
                            }
                        }
                    }
                }
            }
        }