Overriding Controller Behavior For Stock Widgets and Dynamic

Posted by Community Admin on 05-Aug-2018 20:08

Overriding Controller Behavior For Stock Widgets and Dynamic Content Widgets

All Replies

Posted by Community Admin on 20-May-2015 00:00

I was wondering if it is possible to override existing controller behavior, like you can override templates. For instance, say I want to ​modify the model i pass to my list view of dynamic content. Looking through the feather documentation, I found this article which seems to be related: 

How to implement a Master Detail content controller

But overall the documentation on what is going on, especially with Dynamic Content, is a bit sparse. So I am trudging through the source code but, well, there's no actual  controllers there; there's this code:

private void RenameControllers(SiteInitializer initializer)
    var manager = initializer.PageManager;
    var controllerNameProperties = manager.GetControls<ControlData>()
        .Where(c => c.ObjectType == "Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy" || c.ObjectType == "Telerik.Sitefinity.Frontend.Mvc.Infrastructure.Controllers.MvcWidgetProxy, Telerik.Sitefinity.Frontend")
        .SelectMany(c => c.Properties.Where(p => p.Name == "ControllerName"));
 
    foreach (var property in controllerNameProperties)
    
        if (property.Value == "News.Mvc.Controllers.NewsController")
        
            property.Value = "Telerik.Sitefinity.Frontend.News.Mvc.Controllers.NewsController";
        
        else if (property.Value == "ContentBlock.Mvc.Controllers.ContentBlockController")
        
            property.Value = "Telerik.Sitefinity.Frontend.ContentBlock.Mvc.Controllers.ContentBlockController";
        
        else if (property.Value == "Navigation.Mvc.Controllers.NavigationController")
        
            property.Value = "Telerik.Sitefinity.Frontend.Navigation.Mvc.Controllers.NavigationController";
        
        else if (property.Value == "SocialShare.Mvc.Controllers.SocialShareController")
        
            property.Value = "Telerik.Sitefinity.Frontend.SocialShare.Mvc.Controllers.SocialShareController";
        
        else if (property.Value == "DynamicContent.Mvc.Controllers.DynamicContentController")
        
            property.Value = "Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Controllers.DynamicContentController";
        
    

But none of those controllers actually exist in the projects: searching for those strings results in no results.

 So I looked into MvcControllerProxy, but there's not a whole lot going on there.

While I wait for feedback, I'm going to build my project with the source of feather and throw a bunch of break points everywhere to see if I can figure out some of this magic.

There also seems to be some clues here:

feather/Telerik.Sitefinity.Frontend/Mvc/Infrastructure/Controllers/FrontendControllerFactory.cs

 But then that points to SitefinityControllerFactory for creation:

 

public class FrontendControllerFactory : SitefinityControllerFactory, IDisposable
  ...

public override IController CreateController(RequestContext requestContext, string controllerName)
    var baseController = base.CreateController(requestContext, controllerName);

Posted by Community Admin on 21-May-2015 00:00

Well my research has lead me to a different repository: Sitefinity/feather-widgets 

There's a lot of good stuff here especially concerning how the controllers are implemented, but I'm still not sure how to override the existing controllers. 

Posted by Community Admin on 21-May-2015 00:00

From what I cant tell, there's no way to do this by convention. I do believe you can do something like set the controller to use for a widget from the Toolboxes.config:

<add enabled="True" type="Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy" controllerType="Telerik.Sitefinity.Frontend.News.Mvc.Controllers.NewsController" title="News" cssClass="sfNewsViewIcn sfMvcIcn" moduleName="News" ControllerName="Telerik.Sitefinity.Frontend.News.Mvc.Controllers.NewsController" visibilityMode="None" name="News_MVC" />

Posted by Community Admin on 25-May-2015 00:00

Hi Merritt,

Using the code for the widget you want, you can create/extend it as custom widget with the functionality that covers your scenario. than just use that new/custom widget created.

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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 09-Jun-2016 00:00

Hi Merritt,

Sorry to reopen an answered post, but I am pondering the same question... did you figure out how to extend Dynamic Content Widgets, most specifically the controller?

I'm fine creating custom templates (list / detail) that can be selected within the widget when added to the page.

 

I've tried creating a custom controller and inheriting from Telerik.Sitefinity.Frontend.DynamicContent.Mvc.Controllers.DynamicContentController

but most of the properties / actions aren't overridable and can't access private variables.

How did you achieve this other than copy / pasting the code from the Feather Github repo and just renaming the controller.

Given that, how do you register the new controller to execute over the default controller??

 

I look forward to a response as this would help me immensely.

Up to now, I've relied on placing logic inside custom templates which I just don't feel is maintainable and is a little hard trying to test with.

 

 

 

 

 

Posted by Community Admin on 13-Jun-2016 00:00

Hello Brett,

You can get the source code of the Dynamic widget from the GitHub repository and add the functionality you need:
https://github.com/Sitefinity/feather-widgets/tree/master/Telerik.Sitefinity.Frontend.DynamicContent

Depending on the requirements you have, you can create a custom widget to display the content:
https://github.com/Sitefinity/feather-samples/tree/master/SingleDynamicContent
or just modify the template or the model:
http://docs.sitefinity.com/feather-modify-default-templates-used-in-all-dynamic-content-widgets
http://docs.sitefinity.com/feather-modify-built-in-widgets
http://docs.sitefinity.com/feather-dynamic-content

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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 23-Jun-2016 00:00

Hello Manchev,

I want to do a similar thing with Events widget. Along with the default event widget designer I want to add 2 custom fields to the Events widget designer :1. simple text box and 2. a page selector and use the values entered by the user in  these fields in my custom event widget template for display on the website. 

This post says that we need to extend the built-in widget and then use custom widget to add custom functionalities however I am not sure how to start with extending the built in event widget functionality in a custom widget and it would be really helpful if you could provide me some guidance to start with.

I tried using the steps  extend widget designer document for event widget but it does not give any information on how to edit the controller/model as I need to read /write the values from the custom fields.

Posted by Community Admin on 28-Jun-2016 00:00

Hi Ridhi,

The article in question, show how to extend the designer view. If you need to extend the functionality of the controller you needs you need to develop the functionality you need in a custom widget. More about how to create widgets and widget designers in Feather is described here:
http://docs.sitefinity.com/feather-develop-widgets
http://docs.sitefinity.com/feather-widget-designers-framework

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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 30-Jun-2016 00:00

Hi Manchev

Thanks for your response. So you mean I would have to duplicate the entire functionality of events widget in my custom widget so that I can modify the controller to add 2 more properties?? Is there no way I can inherit the built in controller in my custom widget's controller and add my logic for the 2 additional properties?

Posted by Community Admin on 08-Sep-2016 00:00

I'm interested in a solution to this as well...

Posted by Community Admin on 03-Jul-2017 00:00

Bid late to the party, but I am also wondering this. do I really need to copy the whole thing? I want to be able to save some additional settings on the profile page

Posted by Community Admin on 06-Jul-2017 00:00

Kevin, we're also looking into this at them moment. How can we extend the controller to make use of the out of the box setup, with custom additional functionality?

Surely there must be an easier way?

Posted by Community Admin on 06-Jul-2017 00:00

I ended up copying all the required parts (controller models views), I also renamed the controller and the widget name so it does not conflict with the original. it is not ideal for when updates come but it does work perfectly for us now. 

Posted by Community Admin on 11-Jul-2017 00:00

Joining the party...

If we don't inherit from DynamicContentController

The Model Helper: github.com/.../DesignerModelHelper.cs

Will fail at line 152. Because the controller is not of the correct type. I am seeing this in stock widget designer with method calls like Model.ContentTypeDisplayNamePlural(). Which will cause a HTTP 500 Error.

Making the Index and Details Actions on the DynamicContentController overridable might help.

My only solution is to c&p everything, rename, and hack up the widget designer.

Posted by Community Admin on 05-Oct-2017 00:00

My small contribution after having been able to hook a custom Model on a Stock Widget.

Following resources helped me in order to make it. But keep in mind that depending on the way the stock widget was built and customization needed you could need to also create a custom controller (not mandatory but can happen).

Example i was able to override AccountActivationModel and LoginFormModel but I had to use a custom controller for RegistrationModel and ProfileModel.

Hope that will help.

Here are resources.

 

 

This thread is closed