Oct 3, 2013 at 12:13 AM
Edited Oct 3, 2013 at 12:14 AM
I'm using Orchard CMS 1.6.1
I added a new field to the hidden part of a Content Type via migrations:
ContentDefinitionManager.AlterPartDefinition("EventItem", builder => builder
.WithField("HiddenEvent", cfg => cfg
.WithDisplayName("Set as a Hidden Event")
.WithSetting("BooleanFieldSettings.Hint","Check to hide this Event from all default views (calendar, list, map, etc.)")));
My biggest question is whether it would be possible to set a default value for all existing Content Items. I tried this, but it doesn't seem to work:
var publishedEventItems = _contentManager.Query().ForType("EventItem").ForVersion(VersionOptions.Published).List();
if (publishedEventItems != null)
foreach (var eventItem in publishedEventItems)
_eventDataService.SetFieldValue<bool>(eventItem, "HiddenEvent", false);
I need to do this because I will be updating queries, functions, etc to take the new field as a filter/flag. Having the field as undefined is going to cause some problems.
Which actually leads me to a couple of other questions regarding Orchard Queries:
1.) What is the best way to fetch/get/retrieve an existing Orchard Query? I used the titlepart to get the ID but I'm not sure if that is best.
2.) Is it possible to use NOT conditionals for values in a Query FilterRecord? To explain further, I want this because a boolean field has 3 values: undefined, true or false. If I set the filter to finding items which are false, it abandons items which have
undefined values. But if I set it to NOT true, I will get items which are both undefined and false.
Here is my code (doesn't seem to work as well):
var upcomingEventQueryRecord = _titleRepository.Fetch(t => t.Title == "Upcoming Events").FirstOrDefault().ContentItemRecord;
if (upcomingEventQueryRecord != null && upcomingEventQueryRecord.ContentType.Name == "Query")
var filterHiddenRecord = new FilterRecord
Category = "EventItemContentFields",
Type = "EventItem.HiddenEvent",
Description = "Event not Hidden",
Position = 2,
State = "<Form><Description>Event not Hidden</Description><Value>No</Value></Form>"
var upcomingEventsQuery = _contentManager.Get(upcomingEventQueryRecord.Id);
var filterGroup = upcomingEventsQuery.As<QueryPart>().FilterGroups.FirstOrDefault();
Any piece of advise or information would be highly appreciated. Thanks!