Skip to content

Commit

Permalink
Add option to ignore config by editorAlias or item name #178
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Oct 20, 2020
1 parent 29f5943 commit d89974c
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion uSync8.Core/Serialization/Serializers/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ protected override SyncAttempt<IDataType> DeserializeCore(XElement node, SyncSer
}

// config
details.AddRange(DeserializeConfiguration(item, node));
if (ShouldDeserilizeConfig(name, editorAlias, options))
{
details.AddRange(DeserializeConfiguration(item, node));
}

details.AddNotNull(SetFolderFromElement(item, info.Element("Folder")));

return SyncAttempt<IDataType>.Succeed(item.Name, item, ChangeType.Import, details);
Expand Down Expand Up @@ -270,5 +274,36 @@ protected override void DeleteItem(IDataType item)

protected override string ItemAlias(IDataType item)
=> item.Name;



/// <summary>
/// Checks the config to see if we should be deserializing the config element of a data type.
/// </summary>
/// <remarks>
/// a key value on the handler will allow users to add editorAliases that they don't want the
/// config importing for.
/// e.g - to not import all the colour picker values.
/// <code>
/// <Add Key="NoConfigEditors" Value="Umbraco.ColorPicker" />
/// </code>
///
/// To ignore just specific colour pickers (so still import config for other colour pickers)
/// <code>
/// <Add Key="NoConfigNames" Value="Approved Colour,My Colour Picker" />
/// </code>
/// </remarks>
private bool ShouldDeserilizeConfig(string itemName, string editorAlias, SyncSerializerOptions options)
{
var noConfigEditors = options.GetSetting("NoConfigEditors", string.Empty);
if (!string.IsNullOrWhiteSpace(noConfigEditors) && noConfigEditors.InvariantContains(editorAlias))
return false;

var noConfigAliases = options.GetSetting("NoConfigNames", string.Empty);
if (!string.IsNullOrWhiteSpace(noConfigAliases) && noConfigAliases.InvariantContains(itemName))
return false;

return true;
}
}
}

0 comments on commit d89974c

Please sign in to comment.