How to pass guid between definitions?
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.
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/"
);
var requestContext =
this
.GetRequestContext();
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
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)
.....
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
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>
...
public
abstract
class
BaseCategoriesDataProvider : ContentDataProviderBase
...
public
override
IDataItem GetItemFromUrl(Type itemType,
string
url,
out
string
redirectUrl)
...
GetItemFromUrl
method and try to browse URL like
this
localhost:60876/.../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
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
...
No data provider decorator could be found for the provider 'DynamicModule.ns.Wrapped_DefaultCategoryDataProvider_d9d39c612cc0432692a8111b1899128b'. The method 'GetSecurityRoot()' has to be overridden and implemented.
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
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.
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