@Resource(name = "blStaticMapNamedOperationComponent")
protected StaticMapNamedOperationComponent operationMap;
@Override
public void addImageThumbnailField(ListGrid listGrid, String urlField) {
listGrid.getHeaderFields().add(new Field()
.withName("thumbnail")
.withFriendlyName("Asset_thumbnail")
.withFieldType(SupportedFieldType.STRING.toString())
.withOrder(Integer.MIN_VALUE)
.withColumnWidth("50px")
.withFilterSortDisabled(true));
for (ListGridRecord record : listGrid.getRecords()) {
// Get the value of the URL
String imageUrl = record.getField(urlField).getValue();
// Prepend the static asset url prefix if necessary
String staticAssetUrlPrefix = staticAssetService.getStaticAssetUrlPrefix();
if (staticAssetUrlPrefix != null && !staticAssetUrlPrefix.startsWith("/")) {
staticAssetUrlPrefix = "/" + staticAssetUrlPrefix;
}
if (staticAssetUrlPrefix == null) {
staticAssetUrlPrefix = "";
} else {
imageUrl = staticAssetUrlPrefix + imageUrl;
}
MediaField mf = (MediaField) new MediaField()
.withName("thumbnail")
.withFriendlyName("Asset_thumbnail")
.withFieldType(SupportedFieldType.IMAGE.toString())
.withOrder(Integer.MIN_VALUE)
.withValue(imageUrl);
// Add a hidden field for the large thumbnail path
record.getHiddenFields().add(new Field()
.withName("cmsUrlPrefix")
.withValue(staticAssetUrlPrefix));
record.getHiddenFields().add(new Field()
.withName("thumbnailKey")
.withValue("?smallAdminThumbnail"));
record.getHiddenFields().add(new Field()
.withName("servletContext")
.withValue(BroadleafRequestContext.getBroadleafRequestContext().getRequest().getContextPath()));
// Set the height value on this field
mf.setHeight(operationMap.getNamedOperations().get("smallAdminThumbnail").get("resize-height-amount"));