Extending Relationships within Kentico

Trevor Fayas / November 12, 2018
Extending Relationships within Kentico

One of the things I’m known in the Kentico community is my desire to build useful tools for developers so they can leverage Kentico’s features to a greater degree of ease and scope.  I’ve created tools such as: 

I’ve also created various Portal tools such as:

With Kentico announcing a move towards MVC, my focus is also moving more towards tools that will help you structure your data in a way that will work well with building sites using MVC technology.  My latest tool (arriving soon) is a Relationship Extended module.  I've highlighted all the improvements it will make below. 

Improving Categories 

As many of you know, Kentico has a very nice Category module, and categories are a primary way of organizing your data.  However, one major issue I have found with Categories is they are tied to the Document, and not the Node. On the content tree, each element is a Node, but it can have multiple documents.  A Document is a localized flavor of that node, so if you have English and Spanish on your site, you will potentially have 2 documents to the single node.

However, organization rarely ‘changes’ with language.  A News article will be a Technology-type article whether it’s in English or Spanish, or a product will be one category or another, whether it’s in German or French. So part of my module installs a new class, the "Tree Category."  This is the same as Document Category except it has a NodeID instead of a DocumentID.  To use this, I’ve also updated the Advanced Category Selector to have a default option of "Save Type" of "Node Category," so you can use the tool to automatically relate these objects.

New UI

Another thing that is included with this module is a new UI Template "Edit Categories" which is a UI Page version of the Advanced Category Selector, so you can have categories in a special UI tab instead of on the Form (which required a Field without database representation on each page type you want to use it on). You can learn how to create User Interfaces on Kentico Documentation.

New Macro Methods

To allow for easier usage of your Categories if you are using the Portal Method (or even in the Document Queries), I have also included a set of new Macro Methods to generate the "WHERE" conditions.  These helper functions automatically handle any potential SQL injection issues, for Document and Node Categories they automatically convert Code Names and Guids to IDs for faster lookups, and some other nice things. 

Related Pages - Extended

One way to relate objects is through Related Pages.  Kentico has a Node to Node relationship table that you can link nodes with specifically typed relationships (say a “Banner” relationship to link Banner pages to a page).  However, there are 2 main issues with Kentico’s default implementation. 

Issues with Normal Page Relationships

Normal page relationships (General -> Related Pages) can be added through the tab and can be applied across page types.  However, you can’t order these relationships, meaning you can add “Banners” to a page, but you can’t sort them in different ways. 

Issues with Adhoc Related Pages

You can make Adhoc Relationships by adding a field of “Page” type to a page type.  This allows you to add pages on the Form tab, and with these you can sort them.  But it’s on the specific page types that you assign it, so you can’t have these relationships across page types, and it’s also very difficult to use these relationships in the UI because the Relationship Name is a mixture of the page type’s code name and the field’s GUID.  Messy. 

Issues with both default implementations

If these limitations weren’t enough, both methods share two very major flaws:  

  • Can’t limit the page types you can select... which almost goes against the idea of defining relationship types, why would you allow a “Folder” to be used in a “Banner” relationship? 
  • Can only add pages one at a time, which makes for a very length selectin processes if there’s more than a couple items you are relating

Out with the Old, in with the New

To remedy all these things, I’ve created two new pieces.  A Relationship Name Extended UI page and a UI Template: Edit Relationships.

The Relationship Name Extended is to allow you to create Adhoc relationships, since the default UI doesn’t allow you to create these normally, and only Adhoc relationships can be sorted.

The Edit Relationship Template then allows you to create UI elements to handle these relationships.
Please contact HBS an inquiry@hbs.net for a copy of a demonstration of this the new Relationship Name Extended!
Trevor Fayas
About the Author


Trevor Fayas
Senior Software Engineer I

Trevor Fayas is a Senior Software Engineer I at Heartland Business Systems and a 2018 Kentico MVP. He is ranked in the top 10 Kentico Developer Network Q&A Contributors, and has published multiple tools on the Kentico Marketplace.  Trevor’s passion is to help build and equip Kentico users and developers with the tools to really take their site to the next level.

Comments
Blog post currently doesn't have any comments.