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?
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.
The main uSync processes, work through the grid, and when they hit this element they identify the editor alias as media
As we are in the grid, uSync then looks for a mapper called Umbraco.Grid.media
This finds our GridImageMapper (because that is the editorAlias it supports).
The GridImageMapper's GetDependencies method is calles with the json from the value property.
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<JObject>(value.ToString());
var udiString = image.Value<string>("udi");
if (!string.IsNullOrWhiteSpace(udiString))
{
var dependency = CreateDependency(udiString, flags);
if (dependency != null)
return dependency.AsEnumerableOfOne();
}
return Enumerable.Empty<uSyncDependency>();
}
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)
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
};
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.
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
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:
so what uSync does is -
media
Umbraco.Grid.media
The GridImageMapper's GetDependencies method is calles with the json from the value property.
the GridImageMapper then parses this json and returns a list of dependent items.
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)
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
but I've also tried
I shall carry on playing.
Thanks
Andy
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.gUmbraco.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 becomeUmbraco.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.Hi Kevin,
All sorted as normal thanks for the help!
Thanks Andy
is working on a reply...