Copied to clipboard

Flag this post as spam?

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


  • Andy Felton 185 posts 484 karma points c-trib
    Feb 25, 2020 @ 15:56
    Andy Felton
    0

    Custom grid and publishing

    Hi,

    Know I should read the documents first but hit an issue this morning and wanted to check (haven't had a chance to come back to it yet!).

    We're using a Custom Grid and this morning I published some content and the images in the custom Grid never got pushed. Would this require a mapper and if so do you have an example?

    Many Thanks

    Andy

  • Kevin Jump 2311 posts 14697 karma points MVP 7x c-trib
    Feb 26, 2020 @ 09:34
    Kevin Jump
    1

    Hi Andy,

    it depends a little on how custom it is - but in general you will need to implement a mapper for the type.

    uSync uses ValueMappers to work out what content/media etc is needed be to pushed so if your custom grid element is storing the information in JSON then you will need to write your own, that gets picked up uSync when it does its checks.

    A good example of what this might look like is the Grid Image mapper, which finds the images inside the gird.

    https://github.com/KevinJump/uSync8/blob/v8/8.2/uSync8.ContentEdition/Mapping/Mappers/GridImageMapper.cs

    Grid images, are stored in in the grid like this:

    {
      "value": {
        "id": 1206,
        "udi": "umb://media/5145c65cd44045cdbc9dbe953d064d82",
        "image": "/media/lldekuka/9464666791_2003908714_o.jpg"
      },
      "editor": {
        "name": "Image",
        "alias": "media",
        "view": "media",
        "render": null,
        "icon": "icon-picture",
        "config": {}
      }
    },
    

    so what uSync does is -

    1. The main uSync processes, work through the grid, and when they hit this element they identify the editor alias as media
    2. As we are in the grid, uSync then looks for a mapper called Umbraco.Grid.media
    3. This finds our GridImageMapper (because that is the editorAlias it supports).
    4. The GridImageMapper's GetDependencies method is calles with the json from the value property.

    5. the GridImageMapper then parses this json and returns a list of dependent items.

      Public override IEnumerable<uSyncDependency> GetDependencies(object value, string editorAlias, DependencyFlags flags)
      {
          if (value == null) return Enumerable.Empty<uSyncDependency>();
      
      
      
      var image = JsonConvert.DeserializeObject&lt;JObject&gt;(value.ToString());
      
      
      var udiString = image.Value&lt;string&gt;("udi");
      if (!string.IsNullOrWhiteSpace(udiString))
      {
          var dependency = CreateDependency(udiString, flags);
          if (dependency != null)
              return dependency.AsEnumerableOfOne();
      }
      
      
      return Enumerable.Empty&lt;uSyncDependency&gt;();
      
      }

    So if you go down this road the tip here is to Inherit SyncValueMapperBase because that has functions like CreateDependency that let you pass the Udi value in and does all the work.


    If you are not storing json, but a list of links or rich text, then you might be able to create a value mapper that inherits an existing one. (and just has a diffrent list of editor aliases) - so its probibly worth just checking the existing mappers

    (this reminds me we need to write a generic one you can configure that's how Translation Manager does it)

  • Andy Felton 185 posts 484 karma points c-trib
    Feb 26, 2020 @ 18:30
    Andy Felton
    0

    Hi,

    That's a great response really useful. Our format is JSON so will need a mapper. Is the process the same to add content we're dependent on (not media)?

    I've started doing the code and I can see my Editors function getting hit but the GetDependencies is never called - any ideas or is there debugging I can turn on?

    My editors at the moment looks like

        public override string[] Editors => new string[] {
            $"{Constants.PropertyEditors.Aliases.Grid}.media"
        };
    

    but I've also tried

        public override string[] Editors => new string[] {
            Constants.PropertyEditors.Aliases.Grid
        };
    

    I shall carry on playing.

    Thanks

    Andy

  • Kevin Jump 2311 posts 14697 karma points MVP 7x c-trib
    Feb 26, 2020 @ 19:01
    Kevin Jump
    0

    Another lesson for me in "You can never have to much logging" :(

    The grid mapper calculates what the alias might be in this function : https://github.com/KevinJump/uSync8/blob/v8/8.2/uSync8.ContentEdition/Mapping/Mappers/GridMapper.cs#L178

    so it will use the alias value e.g Umbraco.Grid.alias , and if that isn't found it will look for one based on the view - it trims any .cshtml values - and takes the name so /myviews/someview.html would become Umbraco.Grid.someview.

    Things to note, the dependencies are not checked by a standard uSync event, only by publisher and the uSync.Exporter will also calculate dependencies.

  • Andy Felton 185 posts 484 karma points c-trib
    Feb 27, 2020 @ 14:29
    Andy Felton
    0

    Hi Kevin,

    All sorted as normal thanks for the help!

    Thanks Andy

Please Sign in or register to post replies

Write your reply to:

Draft