Runtime error when trying to add container widget to zone in homepage layer.

Topics: General, Troubleshooting
Aug 22, 2011 at 1:59 AM
Edited Aug 23, 2011 at 1:56 AM

Hi all,

Sorry for posting this here, but I seem to get more response here than the issue tracker. I hope someone can help.

A bit of background on what I am trying to achieve, I'm trying to display a slider on the homepage (basically a ul li that holds either an image or HTML.

So firstly I have created a custom content type, which contains the body part and the image field. This type has the parts Body, Common and Containable (as I want to show in a container widget).

Next I created a new content type to hold the containable content types above. This content type, called "Normal List" contains the parts Common and Container. All created fine.

When I actually go to add a container widget to a Zone using the Widgets screen I get an error. See  screenshot on my issue here, http://orchard.codeplex.com/workitem/18090

I've looked into the code base and it looks as though the code cannot load the TypeDefinition object when it tries to create the SelectList which allows the user to select the containable part to display within the widget.

The error is happening on this line d:\TeamCity\Projects\Orchard-Defaul

t\src\Orchard.Web\Core\Containers\Drivers\ContainerWidgetPartDriver.cs:68

I've done some debugging to try and find the error and the x.ContentItem.TypeDefinition is null, so when it tries to load the DisplayName it fails.

var listItems = containers.Count() < 1
? new[] {new SelectListItem {Text = T("(None - create container enabled items first)").Text, Value = "0"}}
: containers.Select(x => new SelectListItem {
Value = Convert.ToString(x.Id),
Text = x.ContentItem.TypeDefinition.DisplayName + ": " + x.As<IRoutableAspect>().Title,
Selected = x.Id == model.Part.Record.ContainerId,
});

I could not find how it loads the TypeDefinition and there are no foreign keys on the tables, I gather they are linked by name. We have a record for the NormalList in the table CMS_Orchard_Framework_ContentTypeRecord and also for the table CMS_Settings_ContentTypeDefinitionRecord so I'm unsure why this is not loading.
I'm hoping I'm just missing something but it's pretty critical that I can create containable content types and then place in container widget. I'm currently having to create lists with a GUID as the URL so noone can actually see the page.
Please help,
Kevin
Coordinator
Aug 22, 2011 at 8:13 PM

Did you try using a regular List to do the containement?

Aug 23, 2011 at 1:48 AM

Hi Bertrand,

Yes that's how I've got around the issue, however I don't want a page for my list, which a list contains as it has the routable part.

I just want to display a slider of images or HTML content, which is on our homepage. I've had to set the list page as a GUID url so no one will guess it.

So this is a bug then and not me adding the wrong parts?

Thanks,

Kevin

Coordinator
Aug 23, 2011 at 1:51 AM

Not exactly a bug. You could remove the routable part, or override that route so it really can't be navigated to.

Aug 23, 2011 at 1:54 AM

Wow that was the quickest response yet, thanks!

Ok so I thought about that but I'm using the lists for something else. I suppose I could override the route but I was hoping by creating a custom container content type that would allow me to display containable content types out of the box.

BTW I do appreciate all of responses I get, I was struggling coming to grips with some of the concepts but I'm growing to like the CMS more and more day by day so thanks.

Aug 23, 2011 at 1:43 PM

From what you're describing, it sounds like the FeaturedItemSlider module that I created might work for you. Could be worth checking out anyway: http://www.orchardproject.net/gallery/List/Modules/Orchard.Module.FeaturedItemSlider

Sep 14, 2011 at 3:03 PM

I was facing same error. My requirement is to have a list that I can use in a container widget, where the content type of the list is also a "container". In my case the list is a "Catalog List" that contains a "Product" that contains any number of "DataSheet Link".

The null reference is caused by x.As<IRoutableAspect>() being called for the Product content type which is seen as a container but is not of type IRoutableAspect. I solved by filtering out non IRoutebleAspect containers as follows:

var listItems = containers.Count() < 1
  ? new[] {new SelectListItem {Text = T("(None - create container enabled items first)").Text, Value = "0"}}
  : containers
  .Where(x => x.As<IRoutableAspect>() != null)
  .Select(x => new SelectListItem {
      Value = Convert.ToString(x.Id),
      Text = x.ContentItem.TypeDefinition.DisplayName + ": " + x.As<IRoutableAspect>().Title,
      Selected = x.Id == model.Part.Record.ContainerId,
  });

 

Hope this helps,

Edoardo