Created
April 20, 2021 16:48
-
-
Save leekelleher/cfa4f3585ea0616241f22b3508f06e99 to your computer and use it in GitHub Desktop.
Contentment: Templated Label prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright © 2021 Lee Kelleher. | |
* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | |
using System.Collections.Generic; | |
using Umbraco.Core.IO; | |
using Umbraco.Core.PropertyEditors; | |
namespace Umbraco.Community.Contentment.DataEditors | |
{ | |
internal sealed class TemplatedLabelConfigurationEditor : ConfigurationEditor | |
{ | |
public TemplatedLabelConfigurationEditor() | |
: base() | |
{ | |
Fields.Add( | |
"notes", | |
"Template", | |
"Enter the AngularJS template to be displayed for the label.", | |
IOHelper.ResolveUrl(CodeEditorDataEditor.DataEditorViewPath), | |
new Dictionary<string, object> | |
{ | |
{ CodeEditorConfigurationEditor.Mode, "razor" }, | |
{ "minLines", 20 }, | |
{ "maxLines", 30 }, | |
}); | |
Fields.Add(new HideLabelConfigurationField()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright © 2021 Lee Kelleher. | |
* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | |
using System.Collections.Generic; | |
using Umbraco.Core; | |
using Umbraco.Core.PropertyEditors; | |
namespace Umbraco.Community.Contentment.DataEditors | |
{ | |
public sealed class TemplatedLabelDataEditor : IDataEditor | |
{ | |
internal const string DataEditorAlias = Constants.Internals.DataEditorAliasPrefix + "TemplatedLabel"; | |
internal const string DataEditorName = Constants.Internals.DataEditorNamePrefix + "Templated Label"; | |
internal const string DataEditorViewPath = NotesDataEditor.DataEditorViewPath; | |
internal const string DataEditorIcon = "icon-fa fa-codepen"; | |
public string Alias => DataEditorAlias; | |
public EditorType Type => EditorType.PropertyValue; | |
public string Name => DataEditorName; | |
public string Icon => DataEditorIcon; | |
public string Group => Constants.Conventions.PropertyGroups.Display; | |
public bool IsDeprecated => false; | |
public IDictionary<string, object> DefaultConfiguration => default; | |
public IPropertyIndexValueFactory PropertyIndexValueFactory => new DefaultPropertyIndexValueFactory(); | |
public IConfigurationEditor GetConfigurationEditor() => new TemplatedLabelConfigurationEditor(); | |
public IDataValueEditor GetValueEditor() | |
{ | |
return new ReadOnlyDataValueEditor | |
{ | |
ValueType = ValueTypes.Integer, | |
View = DataEditorViewPath, | |
}; | |
} | |
public IDataValueEditor GetValueEditor(object configuration) | |
{ | |
var hideLabel = false; | |
if (configuration is Dictionary<string, object> config && config.ContainsKey(HideLabelConfigurationField.HideLabelAlias) == true) | |
{ | |
hideLabel = config[HideLabelConfigurationField.HideLabelAlias].TryConvertTo<bool>().Result; | |
} | |
return new ReadOnlyDataValueEditor | |
{ | |
Configuration = configuration, | |
HideLabel = hideLabel, | |
ValueType = ValueTypes.Integer, | |
View = DataEditorViewPath, | |
}; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright © 2021 Lee Kelleher. | |
* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ | |
using System; | |
using Umbraco.Core; | |
using Umbraco.Core.Models.PublishedContent; | |
using Umbraco.Core.PropertyEditors; | |
namespace Umbraco.Community.Contentment.DataEditors | |
{ | |
public sealed class TemplatedLabelValueConverter : PropertyValueConverterBase | |
{ | |
public override bool IsConverter(IPublishedPropertyType propertyType) => propertyType.EditorAlias.InvariantEquals(TemplatedLabelDataEditor.DataEditorAlias); | |
public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.None; | |
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(object); | |
public override bool HasValue(IPublishedProperty property, string culture, string segment) => false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment