So I added everything; however, when I try to add the widget on Kentico's UI is is not showing. In other words, there is no option to select CTAList when I try to add a new widget to the screen. Here is what I have:
CTAListController.cs
using AE.Web.Gwic.Controllers.Widgets.CTAListWidget;
using AE.Web.Gwic.Models.Kentico.Extensions;
using AE.Web.Gwic.Models.Widgets.CTAListWidget;
using CMS.DocumentEngine;
using CMS.Helpers;
using CMS.DocumentEngine.Types.Gwic;
using Kentico.PageBuilder.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
[assembly: RegisterWidget("AE.Gwic.Web.Widgets.CallToActionWidget", typeof(CTAListWidgetController), "Call To Action List", Description = "", IconClass = "icon-picture")]
namespace AE.Web.Gwic.Controllers.Widgets.CTAListWidget
{
public class CTAListWidgetController : WidgetController<CTAListWidgetProperties>
{
public ActionResult Index()
{
//Set variables
List<CallToAction> ctaItems = new List<CallToAction>();
var defaultLayout = "_CTAList_Carousel";
var layout = defaultLayout;
//Get properties
var props = GetProperties();
//Set view name
if (!string.IsNullOrEmpty(props.Layout))
{
layout = props.Layout;
}
var viewName = $"Widgets/CTAListWidget/{layout}";
if (!this.ViewExists(viewName))
{
viewName = $"Widgets/CTAListWidget/{defaultLayout}";
}
//Get the selected list and iterate over the CTA Items
Guid selectedListGuid = props.Pages.FirstOrDefault().NodeGuid;
var selectedList = CTAListProvider.GetCTALists().WhereEquals(nameof(TreeNode.NodeGUID), selectedListGuid).TopN(1).Published().FirstOrDefault();
if (selectedList != null)
{
var childrenGuids = selectedList.Related_CTAItemList.Split(new[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
ctaItems = CallToActionProvider.GetCallToActions().WhereIn(nameof(TreeNode.NodeGUID), childrenGuids).ToList();
}
//Set the view Model
var ctaListViewModel = new CTAListWidgetModel
{
Title = selectedList.Title,
Image = selectedList.Image,
ImageAltText = selectedList.ImageAltText,
CallToActionItems = ctaItems
};
return PartialView(viewName, ctaListViewModel);
}
}
}
CTAListWidgetProperties.cs
using Kentico.Components.Web.Mvc.FormComponents;
using Kentico.Forms.Web.Mvc;
using Kentico.PageBuilder.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AE.Web.Gwic.Models.Widgets.CTAListWidget
{
public class CTAListWidgetProperties : IWidgetProperties
{
[EditingComponent(PageSelector.IDENTIFIER, ExplanationText = "Select the CTA list")]
[EditingComponentProperty(nameof(PageSelectorProperties.RootPath), "/Global-Widget-Content/CTA-Lists")]
public IList<PageSelectorItem> Pages { get; set; }
/// <summary>
/// The layout
/// </summary>
[EditingComponent(DropDownComponent.IDENTIFIER, ExplanationText = "Select the layout to be used", Order = 1, Label = "Layout", DefaultValue = "")]
[EditingComponentProperty(nameof(DropDownProperties.DataSource), LayoutOptions)]
public string Layout { get; set; }
public const string LayoutOptions =
@";Please select a layout;
_CTAList_Carousel;CTA Carousel;
_HelpTiles;CTA Help Tiles;";
}
}
CTAListWidgetModel.cs
using CMS.DocumentEngine.Types.Gwic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AE.Web.Gwic.Models.Widgets.CTAListWidget
{
public class CTAListWidgetModel
{
public string Title { get; set; }
public string Image { get; set; }
public string ImageAltText { get; set; }
public int SortOrder { get; set; }
public IEnumerable<CallToAction> CallToActionItems { get; set; }
}
}
What might be the issue?