コード例 #1
0
        public static void EnrichItemModel(ItemModel model, string defaultLanguage, bool includeEditMode = false)
        {
            if (model == null)
            {
                return;
            }
            if (model.ContainsKey("TemplateID") && !model.ContainsKey("TemplateIDs"))
            {
                var templateId = new ID((Guid)model["TemplateID"]);
                var template   = TemplateManager.GetTemplate(templateId, global::Sitecore.Context.Database);
                if (template != null)
                {
                    model.Add("TemplateIDs", template.GetBaseTemplates().Select(t => t.ID.Guid).Concat(new[] { templateId.Guid }));
                }
            }

            var scItem = global::Sitecore.Context.Database.GetItem(new ID((Guid)model["ItemID"]));//TODO: should we get it again? Better to fix modelfactory instead

            if (scItem == null)
            {
                return;
            }
            if (!model.ContainsKey("ParentIds"))
            {
                model.Add("ParentIds", scItem?.Paths?.LongID?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Select(id => new Guid(id)));
            }
            if (!model.ContainsKey("ItemUrlExpanded"))
            {
                var urlOptions = LinkManager.GetDefaultUrlOptions();
                urlOptions.AlwaysIncludeServerUrl = false;
                urlOptions.SiteResolving          = true;
                urlOptions.LanguageEmbedding      = scItem.Language.Name == defaultLanguage ? LanguageEmbedding.Never : LanguageEmbedding.Always;
                urlOptions.LowercaseUrls          = true;
                model.Add("ItemUrlExpanded", LinkManager.GetItemUrl(scItem, urlOptions));
            }

            if (includeEditMode)
            {
                var editor = new Dictionary <string, string>();
                foreach (var field in model.Keys)
                {
                    var editfield = EditField(field, scItem);
                    if (!string.IsNullOrEmpty(editfield))
                    {
                        editor.Add(field, editfield);
                    }
                }
                model.Add("FieldEditors", editor);
            }
        }
コード例 #2
0
        private void AddExternalUrlToModel(ItemModel model)
        {
            if (model == null)
            {
                return;
            }
            var  itemGuid     = new Guid(model["ItemID"].ToString());
            Item sitecoreItem = SitecoreItemFacade.GetItem(new ID(itemGuid));

            if (sitecoreItem == null)
            {
                return;
            }

            if (!model.ContainsKey("ExternalUrl"))
            {
                model.Add("ExternalUrl", SitecoreItemFacade.GetItemExternalUrl(sitecoreItem));
            }
        }
コード例 #3
0
        public override bool Update(Guid id, ItemModel itemModel, string language, int version)
        {
            var handler = base.HandlerProvider.GetHandler <UpdateItemHandler>();

            var command = new UpdateItemCommand
            {
                Id        = id,
                Database  = base.DatabaseName,
                ItemModel = itemModel,
                Language  = language,
                Version   = version.ToString()
            };

            handler.Handle(command);

            if (itemModel.ContainsKey("Blob"))
            {
                UpdateMediaItem(itemModel);
            }
            return(true);
        }