public static IEnumerable <Item> RemoveIdFromMultilist(this Item item, string fieldId, string valueToRemove, bool checkSecurity = false)
        {
            var field = item.Fields[fieldId];

            if (field == null)
            {
                return(new Item[0]);
            }

            if (!field.IsOfType <MultilistField>())
            {
                return(new Item[0]);
            }

            var state = SecurityState.Enabled;

            if (!checkSecurity)
            {
                state = SecurityState.Disabled;
            }

            using (new SecurityStateSwitcher(state))
            {
                using (new EditContext(item))
                {
                    MultilistField mlField = field;
                    mlField.Remove(valueToRemove);
                    return(mlField.GetItems());
                }
            }
        }
Exemple #2
0
 public static void Clear(this MultilistField listField)
 {
     foreach (string itemID in listField.Items)
     {
         listField.Remove(itemID);
     }
 }
        private void SwapMultilistFieldValue(Item item, MultilistField field, ID targetItemId, ID newItemId)
        {
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(field, "field");
            Assert.ArgumentNotNull(targetItemId, "targetItemId");
            Assert.ArgumentNotNull(newItemId, "newItemId");

            using (new Sitecore.Data.Items.EditContext(item))
            {
                field.Remove(targetItemId.ToString());
                field.Add(newItemId.ToString());
            }
        }
        /// <summary>
        /// The item that is passed to this method will now be made into a Bucket and all items under it will be automatically organised and hidden.
        /// </summary>
        /// <param name="item">The item that is being turned into a Bucket</param>
        public static void AddSearchTabToItem(Item item)
        {
            MultilistField editors = item.Fields["__Editors"];

            using (new EditContext(item, SecurityCheck.Disable))
            {
                if (!editors.Items.Contains(Constants.SearchEditor))
                {
                    var tempEditors = editors.GetItems();
                    tempEditors.ToList().ForEach(tempEditor => editors.Remove(tempEditor.ID.ToString()));
                    editors.Add(Constants.SearchEditor);
                    tempEditors.ToList().ForEach(tempEditor => editors.Add(tempEditor.ID.ToString()));
                }
            }
        }
        public void CreateBucket(BucketArgs args)
        {
            Event.RaiseEvent("item:bucketing:starting", args, this);
            var            contextItem = args.Item;
            MultilistField editors     = contextItem.Fields["__Editors"];

            using (new EditContext(contextItem, SecurityCheck.Disable))
            {
                if (!editors.Items.Contains(Util.Constants.SearchEditor))
                {
                    var tempEditors = editors.GetItems();
                    tempEditors.ToList().ForEach(tempEditor => editors.Remove(tempEditor.ID.ToString()));
                    editors.Add(Util.Constants.SearchEditor);
                    tempEditors.ToList().ForEach(tempEditor => editors.Add(tempEditor.ID.ToString()));
                }
            }

            Shell.Applications.Dialogs.ProgressBoxes.ProgressBox.Execute(Util.Constants.BucketingText, Util.Constants.BucketingProgressText, Images.GetThemedImageSource("Business/16x16/chest_add.png"), this.StartProcess, new object[] { contextItem });
            Context.ClientPage.SendMessage(this, "item:load(id=" + contextItem.ID + ")");
            Context.ClientPage.SendMessage(this, "item:refreshchildren(id=" + contextItem.Parent.ID + ")");
        }
        protected override void ProcessTemplateItem(TemplateItem templateItem)
        {
            var innerItem = templateItem.InnerItem;

            if (ShouldProcess(innerItem.GetProviderPath(), $"Remove base template(s) '{TemplateItem.Select(t => t.InnerItem).GetProviderPaths()}'"))
            {
                MultilistField baseTemplateField = innerItem.Fields[FieldIDs.BaseTemplate];

                innerItem.Editing.BeginEdit();

                foreach (var template in TemplateItem)
                {
                    // Check if base template already exists, if it does than there's nothing to do.
                    if (baseTemplateField.Contains(template.ID.ToString()))
                    {
                        baseTemplateField.Remove(template.ID.ToString());
                    }
                }

                innerItem.Editing.EndEdit();
            }
        }
Exemple #7
0
        private void UpdateFields(TriggerDetail entity, Item triggerItem)
        {
            triggerItem.Fields["Trigger Key"].Value = entity.TriggerKey;
            DateField startTimeField = triggerItem.Fields["Start Time"];

            if (startTimeField != null)
            {
                startTimeField.Value = Sitecore.DateUtil.ToIsoDate(entity.StartTime);
            }
            triggerItem.Fields["Start Time"].Value = DateUtil.ToIsoDate(entity.StartTime);
            if (entity.EndTime != null || entity.EndTime != DateTime.MinValue)
            {
                triggerItem.Fields["End Time"].Value = DateUtil.ToIsoDate(entity.EndTime);
            }
            else
            {
                triggerItem.Fields["End Time"].Value = "";
            }

            triggerItem.Fields["Schedule Type"].Value   = entity.ScheduleType;
            triggerItem.Fields["Day of Month"].Value    = entity.DayOfMonth.ToString();
            triggerItem.Fields["Repeat Count"].Value    = entity.RepeatCount.ToString();
            triggerItem.Fields["Repeat Interval"].Value = entity.RepeatInterval.ToString();
            triggerItem.Fields["Cron Expression"].Value = entity.CronExpression;
            MultilistField daysOfWeeks = triggerItem.Fields["Days Of Week"];

            Item[] selectedDays = daysOfWeeks.GetItems();
            for (int x = 0; x < selectedDays.Length; x++)
            {
                daysOfWeeks.Remove(selectedDays[x].ID.ToString());
            }
            for (int i = 0; i < entity.DaysOfWeeks.Count; i++)
            {
                daysOfWeeks.Add(entity.DaysOfWeeks[i].itemId);
            }
        }