Skip to content

Commit

Permalink
Potential additional fix for issue #93
Browse files Browse the repository at this point in the history
Overriding Url to ContentHubImageField
  • Loading branch information
jroho authored and blipson89 committed Jul 25, 2021
1 parent b3af5cd commit f4efb8b
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 137 deletions.
267 changes: 143 additions & 124 deletions Source/Synthesis/FieldTypes/ContentHubImageField.cs
Original file line number Diff line number Diff line change
@@ -1,130 +1,149 @@
using System;
using Sitecore.Data;
using Sitecore.Data;
using Sitecore.Data.Items;
using Synthesis.FieldTypes.Interfaces;
using System;

namespace Synthesis.FieldTypes
{
public class ContentHubImageField : ImageField, IContentHubImageField
{
private string _contentId;
private string _thumbnailSrc;
private string _contentType;

public ContentHubImageField(LazyField field, string indexValue) : base(field, indexValue)
{
}

public string ContentId
{
get
{
if (!IsContentHub)
{
return string.Empty;
}

if (_contentId != null)
{
return _contentId;
}

return _contentId = GetAttribute("stylelabs-content-id");
}
}

public string ThumbnailSrc
{
get
{
if (!IsContentHub)
{
return string.Empty;
}

if (_thumbnailSrc != null)
{
return _thumbnailSrc;
}

return _thumbnailSrc = GetAttribute("thumbnailsrc");
}
}

public string ContentType
{
get
{
if (!IsContentHub)
{
return string.Empty;
}

if (_contentType != null)
{
return _contentType;
}

return _contentType = GetAttribute("stylelabs-content-type");
}
}

public override MediaItem MediaItem
{
get
{
if (!IsContentHub)
{
return base.MediaItem;
}

return null;
}
}

public override ID MediaItemId
{
get
{
if (!IsContentHub)
{
return base.MediaItemId;
}

return ID.Null;
}
set
{
if (!IsContentHub)
{
base.MediaItemId = value;
}

throw new InvalidOperationException("Media Item ID cannot be set on a ContentHub image");
}
}

public override bool HasValue
{
get
{
if (!IsContentHub)
{
return base.HasValue;
}

return !string.IsNullOrEmpty(GetAttribute("src"));
}
}


public bool IsContentHub
{
get
{
if (InnerField == null) return false;
return InnerField.Value?.Contains("stylelabs") ?? false;
}
}
}
public class ContentHubImageField : ImageField, IContentHubImageField
{
private string _contentId;
private string _src;
private string _thumbnailSrc;
private string _contentType;

public ContentHubImageField(LazyField field, string indexValue) : base(field, indexValue)
{
}

public string ContentId
{
get
{
if (!IsContentHub)
{
return string.Empty;
}

if (_contentId != null)
{
return _contentId;
}

return _contentId = GetAttribute("stylelabs-content-id");
}
}

public string ThumbnailSrc
{
get
{
if (!IsContentHub)
{
return string.Empty;
}

if (_thumbnailSrc != null)
{
return _thumbnailSrc;
}

return _thumbnailSrc = GetAttribute("thumbnailsrc");
}
}

public string ContentType
{
get
{
if (!IsContentHub)
{
return string.Empty;
}

if (_contentType != null)
{
return _contentType;
}

return _contentType = GetAttribute("stylelabs-content-type");
}
}

public override string Url
{
get
{
if (!IsContentHub)
{
return base.Url;
}

if (_src != null)
{
return _src;
}

return _src = GetAttribute("src");
}
}

public override MediaItem MediaItem
{
get
{
if (!IsContentHub)
{
return base.MediaItem;
}

return null;
}
}

public override ID MediaItemId
{
get
{
if (!IsContentHub)
{
return base.MediaItemId;
}

return ID.Null;
}
set
{
if (!IsContentHub)
{
base.MediaItemId = value;
}

throw new InvalidOperationException("Media Item ID cannot be set on a ContentHub image");
}
}

public override bool HasValue
{
get
{
if (!IsContentHub)
{
return base.HasValue;
}

return !string.IsNullOrEmpty(GetAttribute("src"));
}
}


public bool IsContentHub
{
get
{
if (InnerField == null) return false;
return InnerField.Value?.Contains("stylelabs") ?? false;
}
}
}
}
31 changes: 18 additions & 13 deletions Source/Synthesis/FieldTypes/Interfaces/IContentHubImageField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@
{
public interface IContentHubImageField : IImageField
{
/// <summary>
/// Gets the StyleLabs Content ID
/// </summary>
string ContentId { get; }
/// <summary>
/// Gets the StyleLabs Content ID
/// </summary>
string ContentId { get; }

/// <summary>
/// Gets the Thumbnail Src
/// </summary>
string ThumbnailSrc { get; }
/// <summary>
/// Gets the Thumbnail Src
/// </summary>
string ThumbnailSrc { get; }

/// <summary>
/// Gets the StyleLabs Content Type
/// </summary>
string ContentType { get; }
}
/// <summary>
/// Gets the StyleLabs Content Type
/// </summary>
string ContentType { get; }

/// <summary>
/// Returns if the image is from Content Hub
/// </summary>
bool IsContentHub { get; }
}
}

0 comments on commit f4efb8b

Please sign in to comment.