Pages

Showing posts with label DTGE. Show all posts
Showing posts with label DTGE. Show all posts

Thursday, 4 June 2020

DocTypeGridEditor - Remove default DocType option

As I mentioned in my previous post, I'd be checking to get rid of the default "Doc Type" option in the popup below.
It allows your editors to choose any DocType (marked as "Element") and we can think of reasons why you wouldn't want this option to be available to them.


Even if you didn't mention it in your grid.editors.config.js, the "Doc Type" option is always there.

Turns out it's defined in the manifest-file (App_plugins\DocTypeGridEditor\package.manifest). If you make that gridEditors-property into an empty array, the option will no longer be there.

{
  "gridEditors": [],
  "javascript": [
    "~/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.resources.js",
    "~/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.services.js",
    "~/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js",
    "~/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.directives.js"
  ],
  "css": [
    "~/App_Plugins/DocTypeGridEditor/Css/doctypegrideditor.css"
  ]
}

I hope anyone can benefit from this. See you around!

DocTypeGridEditor - partial view was not found

We've been working with DocTypeGridEditor for years, but just once in a while, there's an issue that takes more than 5 minutes to isolate.

I'm going to assume you know what I'm talking about, for an intro to DTGE will take too much time and can be found elsewhere.

Below is the popup that the users get when adding a control to the grid.


Embed, Image, Macro and Rich text are there by default. Headline and Quote is something we replaced in our base project. Widget is something specific for the project I'm working on.

The problem is the "Doc Type" option. It's not configured in the grid.editors.config.js where you control which controls the editors can pick. It must be added behind the scenes by the DTGE implementation somehow.

For some reason, however, if one of our editors picked "Doc Type" instead of one of the others, it yields the following error:
System.InvalidOperationException: The partial view 'richTextBlock' was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/ContentPage/richTextBlock.aspx
~/Views/ContentPage/richTextBlock.ascx
~/Views/Shared/richTextBlock.aspx
~/Views/Shared/richTextBlock.ascx
~/Views/ContentPage/richTextBlock.cshtml
~/Views/ContentPage/richTextBlock.vbhtml
~/Views/Shared/richTextBlock.cshtml
~/Views/Shared/richTextBlock.vbhtml
~/Views/Partials/richTextBlock.cshtml
~/Views/MacroPartials/richTextBlock.cshtml
~/Views/richTextBlock.cshtml
   at System.Web.Mvc.HtmlHelper.FindPartialView(ViewContext viewContext, String partialViewName, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at Our.Umbraco.DocTypeGridEditor.Web.Extensions.HtmlHelperExtensions.RenderDocTypeGridEditorItem(HtmlHelper helper, IPublishedElement content, String editorAlias, String viewPath, String previewViewPath, Boolean isPreview)
   at ASP._Page_app_plugins_doctypegrideditor_render_doctypegrideditor_cshtml.Execute() in C:\Projects\DPW\Website\ProjectV8.Site\app_plugins\doctypegrideditor\render\doctypegrideditor.cshtml:line 28
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at Umbraco.Web.Mvc.ProfilingView.Render(ViewContext viewContext, TextWriter writer) in d:\a\1\s\src\Umbraco.Web\Mvc\ProfilingView.cs:line 25
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at ASP._Page_Views_Partials_grid_editors_base_cshtml.Execute() in C:\Projects\DPW\Website\ProjectV8.Site\Views\Partials\grid\editors\base.cshtml:line 20

Using the richTextBlock directly works fine, so after some head-scratching I discovered that we usually declare our components as follows:
  {
    "name": "Headline",
    "alias": "headline",
    "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html",
    "icon": "icon-coin",
    "render": "/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml",
    "config": {
      "allowedDocTypes": [
        "headlineBlock"
      ],
      "nameTemplate": "",
      "enablePreview": true,
      "viewPath": "/Views/Partials/Grid/Editors/",
      "previewViewPath": "/Views/Partials/Grid/Editors/",
      "previewCssFilePath": "",
      "previewJsFilePath": ""
    }
  }
Some debugging showed me that the "Doc Type" definition, which is added automatically, even if you want it or not, is this:
  {
    "name": "Doc Type",
    "alias": "docType",
    "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html",
    "render": "/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml",
    "icon": "icon-item-arrangement",
    "config": {
      "allowedDocTypes": [],
      "nameTemplate": "",
      "enablePreview": false,
      "viewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/",
      "previewViewPath": "/Views/Partials/Grid/Editors/DocTypeGridEditor/Previews/",
      "previewCssFilePath": "",
      "previewJsFilePath": ""
    }
  }
The difference is the viewPath-property, ending in /DocTypeGridEditor/, which we do not have. Historical reasons, I guess.

The only way to override this default behavious is by manually adding the DocType configuration to the grid.editors.config.js, with the correct path of course.

Now, if I find a way to eliminate the Doc Type option altogether, I'll let you know.