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

Forums / Project Feather / Overriding Controller Behavior For Stock Widgets and Dynamic Content Widgets

Overriding Controller Behavior For Stock Widgets and Dynamic Content Widgets

10 posts, 1 answered
  1. Merritt
    Merritt avatar
    31 posts
    Registered:
    11 Mar 2011
    20 May 2015
    Link to this post

    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);

  2. Merritt
    Merritt avatar
    31 posts
    Registered:
    11 Mar 2011
    21 May 2015
    Link to this post

    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. 

  3. Merritt
    Merritt avatar
    31 posts
    Registered:
    11 Mar 2011
    21 May 2015
    Link to this post

    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" />

  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Sep 2016
    25 May 2015
    Link to this post
    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
     
    Answered
  5. Brett
    Brett avatar
    10 posts
    Registered:
    07 Apr 2015
    09 Jun in reply to Merritt
    Link to this post

    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.

     

     

     

     

     

  6. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Sep 2016
    13 Jun
    Link to this post
    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
     
  7. Ridhi
    Ridhi avatar
    11 posts
    Registered:
    31 May 2016
    23 Jun in reply to Svetoslav Manchev
    Link to this post

    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.

  8. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Sep 2016
    28 Jun
    Link to this post
    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
     
  9. Ridhi
    Ridhi avatar
    11 posts
    Registered:
    31 May 2016
    30 Jun in reply to Svetoslav Manchev
    Link to this post

    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?

  10. Andres
    Andres avatar
    0 posts
    Registered:
    30 Sep 2013
    08 Sep
    Link to this post
    I'm interested in a solution to this as well...
10 posts, 1 answered