public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var isMultiple = property.PropertyType.DataType.ConfigurationAs <MediaPickerConfiguration>().Multiple; var arrayItems = new List <IEnterspeedProperty>(); if (isMultiple) { var items = property.GetValue <IEnumerable <IPublishedContent> >(culture); foreach (var item in items) { var mediaObject = ConvertToEnterspeedProperty(item); if (mediaObject != null) { arrayItems.Add(mediaObject); } } } else { var item = property.GetValue <IPublishedContent>(culture); var mediaObject = ConvertToEnterspeedProperty(item); if (mediaObject != null) { arrayItems.Add(mediaObject); } } return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var isMultiple = property.PropertyType.DataType.ConfigurationAs <MultiUrlPickerConfiguration>().MaxNumber != 1; var arrayItems = new List <IEnterspeedProperty>(); using (var context = _umbracoContextFactory.EnsureUmbracoContext()) { if (isMultiple) { var items = property.GetValue <IEnumerable <Link> >(culture); if (items != null) { foreach (var item in items) { var linkObject = ConvertToEnterspeedProperty(item, context.UmbracoContext, culture); if (linkObject != null) { arrayItems.Add(linkObject); } } } } else { var item = property.GetValue <Link>(culture); var linkObject = ConvertToEnterspeedProperty(item, context.UmbracoContext, culture); if (linkObject != null) { arrayItems.Add(linkObject); } } } return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var colorValue = string.Empty; var colorLabel = string.Empty; if (UseLabel(property.PropertyType)) { var colorPickerValue = property.GetValue <ColorPickerValueConverter.PickedColor>(culture); colorValue = colorPickerValue.Color; colorLabel = colorPickerValue.Label; } else { colorValue = property.GetValue <string>(culture); colorLabel = colorValue; } var colorPickerProperties = new List <IEnterspeedProperty> { new StringEnterspeedProperty("color", colorValue), new StringEnterspeedProperty("label", colorLabel) }; var properties = colorPickerProperties.ToDictionary(x => x.Name, x => x); return(new ObjectEnterspeedProperty(property.Alias, properties)); }
public static IHtmlContent GetGridHtml(this IHtmlHelper html, IPublishedProperty property, string framework = "bootstrap3") { if (property.GetValue() is string asString && string.IsNullOrEmpty(asString)) { return(new HtmlString(string.Empty)); } var view = "grid/" + framework; return(html.Partial(view, property.GetValue())); }
/// <summary> /// Get linked node value from Multi Url Picker /// </summary> /// <param name="list">List with already linked Nodes</param> /// <param name="node">Content Node to check</param> /// <param name="prop">Property to check</param> /// <param name="nodePath">Complete node Path</param> /// <param name="currentUdi">UDI from current Content Node</param> /// <returns>List of LinkedNodesDataModel</returns> private List <LinkedNodesDataModel> AddRelatedNodeMultiUrlPicker(List <LinkedNodesDataModel> list, IPublishedContent node, IPublishedProperty prop, string nodePath, string currentUdi) { if (prop.GetValue() != null) { foreach (Umbraco.Web.Models.Link link in prop.GetValue() as IEnumerable <Umbraco.Web.Models.Link> ) { list = AddRelatedNode(list, node, null, prop, nodePath, currentUdi, link.Udi.ToString()); } } return(list); }
/// <summary> /// Get linked node value from Multi Node Tree Picker /// </summary> /// <param name="list">List with already linked Nodes</param> /// <param name="node">Content Node to check</param> /// <param name="prop">Property to check</param> /// <param name="nodePath">Complete node Path</param> /// <param name="currentUdi">UDI from current Content Node</param> /// <returns>List of LinkedNodesDataModel</returns> private List <LinkedNodesDataModel> AddRelatedNodeMultiNodeTreePicker(List <LinkedNodesDataModel> list, IPublishedContent node, IPublishedProperty prop, string nodePath, string currentUdi) { if (prop.GetValue() != null) { foreach (IPublishedContent item in prop.GetValue() as List <IPublishedContent> ) { list = AddRelatedNode(list, node, item, prop, nodePath, currentUdi); } } return(list); }
public static object?Value(this IPublishedProperty property, IPublishedValueFallback publishedValueFallback, string?culture = null, string?segment = null, Fallback fallback = default, object?defaultValue = default) { if (property.HasValue(culture, segment)) { return(property.GetValue(culture, segment)); } return(publishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var value) ? value : property.GetValue(culture, segment)); // give converter a chance to return it's own vision of "no value" }
public static MvcHtmlString GetGridHtml(this HtmlHelper html, IPublishedProperty property, string framework = "bootstrap3") { var asString = property.GetValue() as string; if (asString != null && string.IsNullOrEmpty(asString)) { return(new MvcHtmlString(string.Empty)); } var view = "Grid/" + framework; return(html.Partial(view, property.GetValue())); }
public static T Value <T>(this IPublishedProperty property, string culture = null, string segment = null, Fallback fallback = default, T defaultValue = default) { if (property.HasValue(culture, segment)) { // we have a value // try to cast or convert it var value = property.GetValue(culture, segment); if (value is T valueAsT) { return(valueAsT); } var valueConverted = value.TryConvertTo <T>(); if (valueConverted) { return(valueConverted.Result); } // cannot cast nor convert the value, nothing we can return but 'defaultValue' // note: we don't want to fallback in that case - would make little sense return(defaultValue); } // we don't have a value, try fallback if (PublishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var fallbackValue)) { return(fallbackValue); } // we don't have a value - neither direct nor fallback // give a chance to the converter to return something (eg empty enumerable) var noValue = property.GetValue(culture, segment); if (noValue == null) { return(defaultValue); } if (noValue is T noValueAsT) { return(noValueAsT); } var noValueConverted = noValue.TryConvertTo <T>(); if (noValueConverted) { return(noValueConverted.Result); } // cannot cast noValue nor convert it, nothing we can return but 'defaultValue' return(defaultValue); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var value = property.GetValue <string>(); value = _mediaUrlProvider.GetUrl(value); return(new StringEnterspeedProperty(property.PropertyTypeAlias, value)); }
/// <summary> /// Handles the content service unpublished event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e"> The <see cref="PublishEventArgs{IContent}"/> containing information about the event.</param> private void ContentServiceUnPublished(IPublishingStrategy sender, PublishEventArgs <IContent> e) { string alias = BloodhoundPropertyEditor.PropertyEditorAlias; UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current); // Loop through the items and remove the url, value pair from the cache. foreach (IContent content in e.PublishedEntities) { IPublishedContent publishedVersion = helper.TypedContent(content.Id); IPublishedProperty rewriteProperties = publishedVersion .Properties .FirstOrDefault(p => publishedVersion.ContentType.GetPropertyType(p.PropertyTypeAlias).PropertyEditorAlias.Equals(alias)); if (rewriteProperties != null) { List <BloodhoundUrlRewrite> rewrites = rewriteProperties.GetValue <List <BloodhoundUrlRewrite> >(); foreach (BloodhoundUrlRewrite rewrite in rewrites) { UrlRewriteCache.RemoveItem(rewrite.RewriteUrl); } } } }
/// <summary> /// Gets the value of a content's property identified by its alias. /// </summary> /// <param name="content">The content.</param> /// <param name="publishedValueFallback">The published value fallback implementation.</param> /// <param name="alias">The property alias.</param> /// <param name="culture">The variation language.</param> /// <param name="segment">The variation segment.</param> /// <param name="fallback">Optional fallback strategy.</param> /// <param name="defaultValue">The default value.</param> /// <returns>The value of the content's property identified by the alias, if it exists, otherwise a default value.</returns> /// <remarks> /// <para> /// The value comes from <c>IPublishedProperty</c> field <c>Value</c> ie it is suitable for use when rendering /// content. /// </para> /// <para> /// If no property with the specified alias exists, or if the property has no value, returns /// <paramref name="defaultValue" />. /// </para> /// <para> /// If eg a numeric property wants to default to 0 when value source is empty, this has to be done in the /// converter. /// </para> /// <para>The alias is case-insensitive.</para> /// </remarks> public static object?Value( this IPublishedElement content, IPublishedValueFallback publishedValueFallback, string alias, string?culture = null, string?segment = null, Fallback fallback = default, object?defaultValue = default) { IPublishedProperty?property = content.GetProperty(alias); // if we have a property, and it has a value, return that value if (property != null && property.HasValue(culture, segment)) { return(property.GetValue(culture, segment)); } // else let fallback try to get a value if (publishedValueFallback.TryGetValue(content, alias, culture, segment, fallback, defaultValue, out var value)) { return(value); } // else... if we have a property, at least let the converter return its own // vision of 'no value' (could be an empty enumerable) - otherwise, default return(property?.GetValue(culture, segment)); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var value = property.GetValue <string>(); value = PrefixRelativeImagesWithDomain(value); return(new StringEnterspeedProperty(property.PropertyTypeAlias, value)); }
private string TdMntp(IPublishedProperty Property, bool FancyFormat) { var tableData = new StringBuilder(); var items = Property.GetValue <IEnumerable <IPublishedContent> >().ToList(); tableData.AppendLine($"<td>"); if (items.Any()) { //start list tableData.AppendLine($"<ol>"); foreach (var item in items) { tableData.AppendLine($"<li>{item.Name} ({item.DocumentTypeAlias})</li>"); } //end list tableData.AppendLine($"</ol>"); } else { tableData.AppendLine($"<i>No items added</i>"); } tableData.AppendLine($"</td>"); return(tableData.ToString()); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var nodeIds = property.GetValue <string>()?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse); var arrayItems = new List <IEnterspeedProperty>(); if (nodeIds != null) { var umbracoHelper = UmbracoContextHelper.GetUmbracoHelper(); foreach (var nodeId in nodeIds) { var node = umbracoHelper.TypedContent(nodeId); if (node == null) { node = umbracoHelper.TypedMember(nodeId); } if (node == null) { node = umbracoHelper.TypedMedia(nodeId); } var convertedNode = ConvertToEnterspeedProperty(node); if (convertedNode != null) { arrayItems.Add(convertedNode); } } } return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var value = property.GetValue <IPublishedContent>(culture); var contentId = _entityIdentityService.GetId(value, culture); return(new StringEnterspeedProperty(property.Alias, contentId)); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var value = property.GetValue <HtmlString>(culture).ToString(); value = PrefixRelativeImagesWithDomain(value, _enterspeedConfigurationService.GetConfiguration().MediaDomain); return(new StringEnterspeedProperty(property.Alias, value)); }
public static T GetValue <T>(this IPublishedProperty property, string culture) { if (!property.PropertyType.VariesByCulture()) { culture = null; } return((T)property.GetValue(culture)); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var configuration = property.PropertyType.DataType.ConfigurationAs <SliderConfiguration>(); if (configuration.EnableRange) { var range = property.GetValue <Range <decimal> >(culture); var properties = new Dictionary <string, IEnterspeedProperty>(); properties.Add("minimum", new NumberEnterspeedProperty(ConvertToDouble(range.Minimum))); properties.Add("maximum", new NumberEnterspeedProperty(ConvertToDouble(range.Maximum))); return(new ObjectEnterspeedProperty(property.Alias, properties)); } var value = property.GetValue <decimal>(culture); return(new NumberEnterspeedProperty(property.Alias, ConvertToDouble(value))); }
private bool TryGetPropertyAsDbType(IPublishedProperty property, DatabaseType type, out object propertyValue, string dataTypeName) { switch (type) { case DatabaseType.Date: propertyValue = property.GetValue <DateTime>(); return(true); case DatabaseType.Integer: propertyValue = property.GetValue <int>(); return(true); case DatabaseType.Ntext: case DatabaseType.Nvarchar: default: propertyValue = property.DataValue; return(true); } }
public IEnterspeedProperty Convert(IPublishedProperty property) { var value = property.GetValue <string>(); if (DateTime.TryParse(value, out var date) && date == default) { value = null; } return(new StringEnterspeedProperty(property.PropertyTypeAlias, value)); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var value = property.GetValue <decimal>(); var number = 0d; if (double.TryParse(value.ToString(CultureInfo.InvariantCulture), out var n)) { number = n; } return(new NumberEnterspeedProperty(property.PropertyTypeAlias, number)); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var value = property.GetValue <IEnumerable <string> >(culture); var arrayItems = new List <IEnterspeedProperty>(); foreach (var item in value) { arrayItems.Add(new StringEnterspeedProperty(item)); } return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var configuration = property.PropertyType.DataType.ConfigurationAs <MultiNodePickerConfiguration>(); var isMultiple = configuration.MaxNumber != 1; var objectType = configuration?.TreeSource?.ObjectType; if (string.IsNullOrWhiteSpace(objectType)) { throw new Exception($"Missing ObjectType/NodeType for MultiNodeTreePicker: {property.Alias}"); } var arrayItems = new List <IEnterspeedProperty>(); if (isMultiple) { var items = property.GetValue <IEnumerable <IPublishedContent> >(culture); if (items != null) { foreach (var item in items) { var contentObject = ConvertToEnterspeedProperty(item, culture, objectType); if (contentObject != null) { arrayItems.Add(contentObject); } } } } else { var item = property.GetValue <IPublishedContent>(culture); var contentObject = ConvertToEnterspeedProperty(item, culture, objectType); if (contentObject != null) { arrayItems.Add(contentObject); } } return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var value = property.GetValue <string>(); ObjectEnterspeedProperty mediaValue = null; if (!string.IsNullOrWhiteSpace(value) && int.TryParse(value, out var mediaId)) { var media = UmbracoContextHelper.GetUmbracoHelper().TypedMedia(mediaId); mediaValue = ConvertToEnterspeedProperty(media); } return(new ObjectEnterspeedProperty(property.PropertyTypeAlias, mediaValue?.Properties)); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var items = property.GetValue <string[]>(); var arrayItems = new List <IEnterspeedProperty>(); if (items != null) { foreach (var item in items) { arrayItems.Add(new StringEnterspeedProperty(item)); } } return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var isMultiple = property.PropertyType.DataType.ConfigurationAs <DropDownFlexibleConfiguration>().Multiple; var arrayItems = new List <IEnterspeedProperty>(); if (isMultiple) { var items = property.GetValue <string[]>(culture); foreach (var item in items) { arrayItems.Add(new StringEnterspeedProperty(item)); } } else { var value = property.GetValue <string>(culture); if (!string.IsNullOrWhiteSpace(value)) { arrayItems.Add(new StringEnterspeedProperty(value)); } } return(new ArrayEnterspeedProperty(property.Alias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var values = property.GetValue <string>()?.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); var arrayItems = new List <IEnterspeedProperty>(); if (values != null) { foreach (var value in values) { arrayItems.Add(new StringEnterspeedProperty(value)); } } return(new ArrayEnterspeedProperty(property.PropertyTypeAlias, arrayItems.ToArray())); }
public IEnterspeedProperty Convert(IPublishedProperty property) { var value = property.GetValue <string>(); if (!string.IsNullOrWhiteSpace(value) && int.TryParse(value, out var prevalueId)) { value = UmbracoContextHelper.GetUmbracoHelper().GetPreValueAsString(prevalueId); } else { value = null; } return(new StringEnterspeedProperty(property.PropertyTypeAlias, value)); }
public IEnterspeedProperty Convert(IPublishedProperty property, string culture) { var value = property.GetValue<IPublishedContent>(culture); Dictionary<string, IEnterspeedProperty> properties = null; if (value != null) { properties = new Dictionary<string, IEnterspeedProperty> { { "id", new NumberEnterspeedProperty(value.Id) }, { "name", new StringEnterspeedProperty(value.Name) }, { "memberType", new StringEnterspeedProperty(value.ContentType.Alias) } }; } return new ObjectEnterspeedProperty(property.Alias, properties); }