Fixed uQuery GetDictionaryItem method so it doesnt throw exception if the requested item does not exist, and returns fallback string instead.
This commit is contained in:
@@ -3,43 +3,48 @@ using umbraco.cms.businesslogic;
|
||||
|
||||
namespace umbraco
|
||||
{
|
||||
/// <summary>
|
||||
/// Static helper methods, previously this class was UmbracoHelper
|
||||
/// </summary>
|
||||
public static partial class uQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a dictionary item if it exists. Otherwise returns the fallback string.
|
||||
/// </summary>
|
||||
/// <param name="key">The dictionary key.</param>
|
||||
/// <param name="fallback">The fallback.</param>
|
||||
/// <returns>
|
||||
/// A dictionary string or the fallback string
|
||||
/// </returns>
|
||||
public static string GetDictionaryItem(string key, string fallback)
|
||||
{
|
||||
var item = library.GetDictionaryItem(key);
|
||||
return string.IsNullOrEmpty(item) ? fallback : item;
|
||||
}
|
||||
/// <summary>
|
||||
/// Static helper methods, previously this class was UmbracoHelper
|
||||
/// </summary>
|
||||
public static partial class uQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a dictionary item if it exists. Otherwise returns the fallback string.
|
||||
/// </summary>
|
||||
/// <param name="key">The dictionary key.</param>
|
||||
/// <param name="fallback">The fallback.</param>
|
||||
/// <returns>
|
||||
/// A dictionary string or the fallback string
|
||||
/// </returns>
|
||||
public static string GetDictionaryItem(string key, string fallback)
|
||||
{
|
||||
if (Dictionary.DictionaryItem.hasKey(key))
|
||||
{
|
||||
var item = new Dictionary.DictionaryItem(key);
|
||||
return item.Value();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dictionary item for a specified language. Otherwise returns the fallback string.
|
||||
/// </summary>
|
||||
/// <param name="key">The dictionary key.</param>
|
||||
/// <param name="fallback">The fallback.</param>
|
||||
/// <param name="languageId">The language id.</param>
|
||||
/// <returns>
|
||||
/// Returns the value of a dictionary item from a language id, or the fallback string.
|
||||
/// </returns>
|
||||
public static string GetDictionaryItem(string key, string fallback, int languageId)
|
||||
{
|
||||
if (Dictionary.DictionaryItem.hasKey(key))
|
||||
{
|
||||
var item = new Dictionary.DictionaryItem(key);
|
||||
return item.Value(languageId);
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the dictionary item for a specified language. Otherwise returns the fallback string.
|
||||
/// </summary>
|
||||
/// <param name="key">The dictionary key.</param>
|
||||
/// <param name="fallback">The fallback.</param>
|
||||
/// <param name="languageId">The language id.</param>
|
||||
/// <returns>
|
||||
/// Returns the value of a dictionary item from a language id, or the fallback string.
|
||||
/// </returns>
|
||||
public static string GetDictionaryItem(string key, string fallback, int languageId)
|
||||
{
|
||||
if (Dictionary.DictionaryItem.hasKey(key))
|
||||
{
|
||||
var item = new Dictionary.DictionaryItem(key);
|
||||
return item.Value(languageId);
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user