More in this section

Forums / General Discussions / How to pass guid between definitions?

How to pass guid between definitions?

11 posts, 0 answered
  1. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    16 Feb 2011
    Link to this post
    Hi Guys,

    I'm looking for a way how to pass guid of parent element to child definition on back-end side. For example, how Blogs module does.

    I have similar structure - list of catalogs and a list of items. Each catalog may contain several items. The desired behavior is when an appropriate catalog is selected it is necessary to show the list items associated with catalog.

    I made: two definitions CatalogsDefinition and ItemsDefinition and two services for them. Separately it works well.
    However, I can't figure out how do I pass Guid of parent catalog to the ItemsDefinition.

    Can you provide me any example?

    Thanks in advance,
    Anton.
  2. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    21 Feb 2011
    Link to this post
    Hi Guys,

    I've figured out one thing that I should to do. This post describes how to retrieve the data for the front-end pages. It seems, the same behavior has been implemented for back-end pages.

    In the parent definition I have the following code:
    #region Links definition
     
    catalogGridView.LinksConfig.Add(new LinkElement(catalogGridView.LinksConfig)
    {
        Name = "viewCatalogItems",
        CommandName = "view",
        NavigateUrl = RouteHelper.CreateNodeReference(CatalogModule.ItemDefinitionListPageId, true) + "/{{ID}}/"
    });

    It allows loading the page where is the definition for displaying item list. So, should be a way to retrieve the ID of parent element on the ItemDefinition side. Since, the definition is not a control we cannot use to get requestContent method:

    var requestContext = this.GetRequestContext();

    What's next?
    Can the Support team points me in the right direction?
     
    Best regards,
    Anton.
  3. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    01 Nov 2016
    23 Feb 2011
    Link to this post
    Hello Anton,

    First i wanted to ask why don't you still pass {{Url}} and not {{ID}}. Doesn't your catalgos have public SEO friendly URL's - like blogs? If you pass Url as in blogs this autmatically works.
    If you do not make use of these url-s than you can still pass the {{ID}}, the resolving actually happens in the MasterGridView control, which on the other hand calls the DataProvider of the parent item - - say BlogsDataProvider.GetItemFromUrl to resolve the parent item. So i guess in your case you have a custom content povider for the catalogs, so you can override the IDataItem GetItemFromUrl(Type itemType, string url, out string redirectUrl) method. And check if the url - looks like guid,e.g. is parsable as guid to get the item by id not by url. E.g. use GetItem(Type itemType, Guid id) to get the item once you have the parsed Guid.

    Greetings,
    Nikolay Datchev
    the Telerik team
  4. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    24 Feb 2011
    Link to this post
    Hi Nikolay,

    Actually, I have DataProvider that is not based on ContentDataProviderBase. It is derived from Telerik.Sitefinity.Data.DataProviderBase. My provider uses another database and does not use Sitefinity database as storage.

    It provides several methods that allow retrieving data which have not SEO-friendly URLs. Therefore, I'm trying to pass ID instead of URL.

    As far as I understand, my custom provider should implement interface IUrlProvider and realize the method GetItemFromUrl()

    public class CatalogsDataProvider : DataProviderBase, IUrlProvider
    {
             .....
     
            public IDataItem GetItemFromUrl(Type itemType, string url, out string redirectUrl)
            {
                    .....
            }
    }

    However, it does not work.
    When I've attached VS debugger to this method and try to browse URL like this http://localhost:60876/Sitefinity/Content/MyCatalog/Items/F5540989-FB0D-466c-936A-6DB0143A0628/
    this method is never fired.

    What I do wrong?

    Best regards,
    Anton.
  5. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    01 Nov 2016
    24 Feb 2011
    Link to this post
    Hi Anton,

    Actually MasterGridView is trying to work with providers that inherit ContentDataProviderBase. Is it possible that you actually use this ContentDataProviderBase as a base for your provider?

    Greetings,
    Nikolay Datchev
    the Telerik team
  6. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    24 Feb 2011
    Link to this post
    Nikolay,

    >>Is it possible that you actually use this ContentDataProviderBase as a base for your provider?
    I think yes.

    I've implemented Manager class:
        public class CategoriesManager : ContentManagerBase<BaseCategoriesDataProvider>
        {
    ...
    }

    and DataProvider:
    public abstract class BaseCategoriesDataProvider : ContentDataProviderBase
    {
    ...
            public override IDataItem GetItemFromUrl(Type itemType, string url, out string redirectUrl)
            {
                ...
            }
    }

    When I've attached VS debugger toGetItemFromUrl method and try to browse URL like this http://localhost:60876/Sitefinity/Content/MyCatalog/Items/F5540989-FB0D-466c-936A-6DB0143A0628/
    this method is never fired.

    Is there anything that should be implemented\overwritten?

    Best regards,
    Anton.
  7. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    01 Nov 2016
    24 Feb 2011
    Link to this post
    Hi Anton,
    Ok, sorry that this clears in so many steps:
    1) The provider should inherit ContentDataProviderBase
    2) the type of the item that you want to list should implment IHasParent. So the "Item" should implement IHasParent
    All the best,
    Nikolay Datchev
    the Telerik team
  8. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    24 Feb 2011
    Link to this post
    Hi Nikolay,

    I implemented this interface to the CategoryItem type, like this:

        public class CategoryItem : Content, IHasParent
        {
             ....
            Content Parent
            {
                get
                {
                    //some code to get parent item
                }
                set
                {
                   //some code to set parent item
                }
            }
            ...
    }

    Now, when I try to load Sitefinity I get the following error:
    No data provider decorator could be found for the provider 'DynamicModule.ns.Wrapped_DefaultCategoryDataProvider_d9d39c612cc0432692a8111b1899128b'. The method 'GetSecurityRoot()' has to be overridden and implemented.

    As far as I understand, I should implement some Decorator class. I've found this article about implementing decorators:
    http://www.sitefinity.com/40/help/developer-manual/security-implementing-security-decorators.html

    However, my data provider class does not use OpenAccess, it uses LINQ.

    It seems, I should develop a new one decorator class for my DataProvider, right? From which base class it should be derived? Which methods are needed to be overridden?

    Thanks in advance,
    Anton.
  9. Nikolay Datchev
    Nikolay Datchev avatar
    87 posts
    Registered:
    01 Nov 2016
    24 Feb 2011
    Link to this post
    Hi Anton,

    Can you try to override the GetSecurityRoot method in your provider and return null. I think this should do the trick. This is used by the MasterGrifView to try to disable some actions like Create, Delete etc, but if you return null it should skip this logic.

    All the best,
    Nikolay Datchev
    the Telerik team
  10. Anton Mernov
    Anton Mernov avatar
    110 posts
    Registered:
    03 Dec 2008
    25 Feb 2011
    Link to this post
    Hi Nikolay,

    Thanks, that made the trick!

    However, there are a lot of problems to make my custom module work.
    As far as I can see, if your custom module was not based on GenericContent module in Sitefinity 3.7 there is no simple way to move it in Sitefinity 4.

    What if my Category and CategoryItem classes cannot be inherited from Content class? That means, there is no ability to use IHasParent interface and I cannot retrieve Parent element in this case. In Sitefinity 3.7 my model has been written from scratch, I didn't use any base class.

    If I use Content class I need to rewrite too many functionality, implement and override not needed properties and methods that are used in workflow, etc.

    It would be great to have an example that explains how to write custom module which doesn't use GenericContent.
    For instance, if I need just integrate data from external data source and their management in Sitefintiy interface.

    Best regards,
    Anton.
  11. George
    George avatar
    28 posts
    Registered:
    24 Sep 2012
    08 Mar 2011
    Link to this post
    Hello Anton,

    In Sitefinity 4.0 it is recommended to use content because many things are provided out-of-the-box with it (managers, providers) which otherwise you'll have to do from scratch. Regarding your specific scenario, we have a task logged for the article showcasing a module that does not use GenericContent, but it will take some time to be there.

    I can suggest you also to have a look into the JobsIntermediate module shipped as an example within the SDK, it directly inherits from ModuleBase.


    Best wishes,
    George
    the Telerik team
11 posts, 0 answered