Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bo Jacobsen 608 posts 2406 karma points
    Oct 26, 2020 @ 11:36
    Bo Jacobsen
    0

    How to get culture in DocTypeGridEditor

    Hi all.

    Using UmbracoCms 8.8.0 and Our.Umbraco.DocTypeGridEditor 1.2.4

    How do i get the culture?

    Is it possible through the view on the IPublishedElement ?

    There are som scenarios where i need the culture when i use a Content Picker or Multi Url Picker.

    So i created a custom property controller that are used in the grid, inserted with DocTypeGridEditor in the package.manifest like this:

    {
      "propertyEditors": [
        {
          "alias": "Custom.PropertyEditor.Culture",
          "name": "Readonly Culture",
          "icon": "icon-readonly color-red",
          "editor": {
            "view": "~/App_Plugins/CustomPlugin/propertyEditors/readonlyCulture/readonlyCulture.html"
          }
        }
      ],
      "gridEditors": [
        {
          "name": "List",
          "alias": "Custom.GridEditors.List",
          "view": "/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.html",
          "render": "/App_Plugins/DocTypeGridEditor/Render/DocTypeGridEditor.cshtml",
          "icon": "icon-bulleted-list color-green",
          "config": {
            "allowedDocTypes": [ "ListView" ],
            "nameTemplate": "",
            "enablePreview": true,
            "overlaySize": "small",
            "viewPath": "/Views/Partials/DocTypeGridEditor/",
            "previewViewPath": "/Views/Partials/DocTypeGridEditor/Previews/",
            "previewCssFilePath": "",
            "previewJsFilePath": ""
          }
        }
      ],
      "javascript": [
        "~/App_Plugins/CustomPlugin/propertyEditors/readonlyCulture/readonlyCulture.js"
      ]
    }
    

    My controller looks like this:

    (function () {
        "use strict";
    
        function readonlyCulture($scope, $routeParams) {
    
            $scope.model.value = $routeParams.cculture || $routeParams.mculture;   
        }
    
        angular.module("umbraco").controller("Custom.ReadonlyCulture.EditorController", readonlyCulture);
    })();
    

    There is a $routeParams.mculture and a $routeParams.cculture.

    When i am editing the main language i am only getting mculture as expected.

    And when i change to another language i am getting the cculture as expected.

    But when i am using splitview, i get am getting the same result on both documents.

    Example:

    URL: http://localhost:64556/umbraco/#/content/content/edit/1056?mculture=da-DK&cculture=en-US

    Split View: Left -> en-US. Right: da-DK enter image description here

    When i access the grid on both documents i am getting mculture=da-DK and cculture=en-US and can no longer tell the difference, because i do not know which one i am editing.

    I hope someone know what to do :)

    I was told that $scope.model.culture could do it, but not in DTGE. https://our.umbraco.com/forum/using-umbraco-and-getting-started/103020-how-to-get-document-culture-in-controller-to-use-in-grid-when-using-split-view

  • Bo Jacobsen 608 posts 2406 karma points
    Apr 09, 2021 @ 11:29
    Bo Jacobsen
    0

    Now using Umbraco 8.11.1 and DocTypeGridEditor 1.2.7 and having trouble getting the right culture.

    We use a nestedcontent with a grid inside where we use DocTypeGridEditor to make a Breadcrumb.

    This code works in the frontend, but not in the backoffice. Here we are only able to get the main culture.

    public class BreadcrumbSurfaceController : DocTypeGridEditorSurfaceController
    {
        public ActionResult Breadcrumb()
        {
            var model = new BreadcrumbModel();
    
            var assignedContentItem = Umbraco.AssignedContentItem; // This is for the most part returning unpublished content item with an id that do not exists in the backoffice.
            var currentPage = Umbraco.Content(Umbraco.AssignedContentItem.Id);
            if (currentPage != null)
            {
                var culture = currentPage.GetCultureFromDomains(); // This is only returning the main culture in the backoffice
                var ancestors = currentPage.Ancestors().Where(x => x.Level > 1);
    
                // Assigning items to the BreadcrumbModel here
            }
    
    
            return CurrentPartialView(model);
        }
    }
    

    Another issue here is that most of the time Umbraco.AssignedContentItem gives us an unpublished item with an id that do not exists like 1586 and the highest content id we have is like 1281.

    Do anyone got a clue?

Please Sign in or register to post replies

Write your reply to:

Draft