+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to create a custom page widget for my custom module

How to create a custom page widget for my custom module

4 posts, 0 answered
  1. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    10 Jan 2014
    Link to this post
    I created a custom module using Sitefinity Thunder (v1.3.1.0) and it works as expected (Sitefinity 6.2.4910.0). I chose OpenAccess for the ORM but I modified the getters in OpenAccessDataProvider to use my own ORM to fetch the content items.

    My problem is that there is no page widget for my custom module that I can drop onto my pages. I'd like to have a page widget that displays a list of my content items from my custom module (similar to the page widgets for News and Events).

    I looked at the code reference for one of my dynamic modules and saw the code for "Integration example". It looked like something worth trying even though it uses DynamicModuleManager and I am using a custom module. I attached a screenshot of the integration example code I used and modified to try to use for my custom module model OAEvents.Models.OAEventsItem.

    I am able to add the page widget to the toolbox using Sitefinity Thunder and I can also drop the page widget onto a page. However, the widget does not load the content items. The following code is throwing an exception and I don't know how to resolve it:

    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
    Type oaEventsItemType = TypeResolutionService.ResolveType("OAEvents.Models.OAEventsItem");
     
    // Fetch a collection of "live" and "visible" oaEventsItem items.
    var myCollection = dynamicModuleManager.GetDataItems(oaEventsItemType).Where(i => i.Status == ContentLifecycleStatus.Live && i.Visible);


    Here's the exception and part of the stack (I also attached a screenshot):

    [ArgumentNullException: Value cannot be null.
    Parameter name: No persistent type with name OAEvents.Models.OAEventsItem]
    DynamicModule.ns.Wrapped_OpenAccessDynamicModuleProvider_ce74867b9b2141288cb1958c0c209c1b.GetDataItems(Type itemType) +408
    SitefinityWebApp.UserControls.DisplayItems.GetDataItems() in c:\Users\Bo\Documents\Sitefinity\Workspaces\InertiaSitefinity\SitefinityWebApp\UserControls\DisplayItems.ascx.cs:32
    SitefinityWebApp.UserControls.DisplayItems.Page_Load(Object sender, EventArgs e) in c:\Users\Bo\Documents\Sitefinity\Workspaces\InertiaSitefinity\SitefinityWebApp\UserControls\DisplayItems.ascx.cs:17
    System.Web.UI.Control.LoadRecursive() +95


    I know that the string OAEvents.Models.OAEventsItem is correct because if I change it to something bogus, I get an error about the type not being found.

    What is the correct way to create a page widget for my custom module so that it shows my content items in a list view?
  2. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    10 Jan 2014 in reply to Bo Chulindra
    Link to this post
    I'm not sure what I've done to change the error (I rebuilt my projects and restarted the server) but now I'm seeing a different exception (I pasted it at bottom) which is caused by the same line of code. I looked at SitefinityQuery#GetDynamicContent and the problem appears to be that my OAEventsItem class is not of the type Telerik.Sitefinity.DynamicModules.Model.DynamicContent. I changed OAEventsItem to derive from DynamicContent and I got this error when trying to re-install the custom module: Base class 'Telerik.Sitefinity.DynamicModules.Model.DynamicContent' was
    enhanced into 'OAEvents.Models.OAEventsItem', but not used during
    relational metadata creation.



    [VerificationException: Method Telerik.Sitefinity.Data.Linq.SitefinityQuery.GetDynamicContent: type argument 'OAEvents.Models.OAEventsItem' violates the constraint of type parameter 'ActualType'.]
    System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation) +0
    System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation) +430

    [ArgumentException: GenericArguments[0], 'OAEvents.Models.OAEventsItem', on 'System.Linq.IQueryable`1[Telerik.Sitefinity.DynamicModules.Model.DynamicContent] GetDynamicContent[ActualType](Telerik.Sitefinity.Data.DataProviderBase)' violates the constraint of type 'ActualType'.]
    DynamicModule.ns.Wrapped_OpenAccessDynamicModuleProvider_683e0b06e1c24cb5a2fe1601efa34425.GetDataItems(Type itemType) +408
    SitefinityWebApp.UserControls.DisplayItems.GetDataItems() in c:\Users\Bo\Documents\Sitefinity\Workspaces\InertiaSitefinity\SitefinityWebApp\UserControls\DisplayItems.ascx.cs:32
    SitefinityWebApp.UserControls.DisplayItems.Page_Load(Object sender, EventArgs e) in c:\Users\Bo\Documents\Sitefinity\Workspaces\InertiaSitefinity\SitefinityWebApp\UserControls\DisplayItems.ascx.cs:17
    System.Web.UI.Control.LoadRecursive() +95

  3. Bo Chulindra
    Bo Chulindra avatar
    35 posts
    Registered:
    17 Dec 2013
    10 Jan 2014
    Link to this post
    So I realized what I was doing wrong. The integration example was specifically pulling DynamicContent using the DynamicModuleManager to be displayed which is not what I needed. Instead, I simply used my own data provider to pull my content items to be displayed in the grid. However, the resulting list does not have the same functionality as the list widgets for Events and News. For example, I'd like some properties of the content items to be displayed and I'd also like the content items to be clickable to see more details. Does Sitefinity provide some way to do that (for example, re-using whatever UI code Events/News widgets are using) without having to re-implement it myself?

    I attached screenshots for my list and the kind of list I'd like to see.
  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    14 Jan 2014
    Link to this post
    Hi Bo,

    You could check the example of Products Module presented in Sitefinity documentation. In addition you can see how it works using Sitefinity SDK samples.

    In the documentation you will find all the steps how to create and using it in Sitefinity.

    Regards,
    Svetoslav Manchev
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered