-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Potential additional fix for issue #93
Overriding Url to ContentHubImageField
- Loading branch information
Showing
2 changed files
with
161 additions
and
137 deletions.
There are no files selected for viewing
This file contains 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
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; | ||
} | ||
} | ||
} | ||
} |
This file contains 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