I have a content part that provides a begin timestamp and end timestamp option. These 2 fields are used to define a period of time in which the content item should be displayed.
I now have difficulties to implement a skip approach whereas content items should not be displayed / skipped when the period of time does not span the current time.
Digging in the source code and trying to find an entry point for my approach resulted in the following content handler
public class SkipContentHandler : Orchard.ContentManagement.Handlers.ContentHandler
{
protected override void BuildDisplayShape(Orchard.ContentManagement.Handlers.BuildDisplayContext aContext)
{
if (...) // my condition to process only content shapes which need to be skipped
{
aContext.Shape = null; // return null shape to skip it
}
}
}
This works but there are several side effects
- I had to alter the source code of
BuildDisplayContext
as theShape
is normally read only - List shape may displayed a wrong pager when it contains content items with my content part because the
Count()
call inContainerPartDriver.Display()
is executed beforeBuildDisplay()
- calling the URL of a content item that is skipped results in an exception because
View(null)
is abigious
So, what would be the correct approach here or is there any module in existence that does the job? I couldn't find one.
Count
as you mentioned. So paging probably fails, and probably more with that – Herr.List()
-Method to filter for that fields before callingSlice()
. After that you would need to register the custom ContentQuery class with autofac; check Orchard.ContentManagement.ContentModule. If you're interested in that approach I could create a small demo. – Petaliferous