[MGNLSTK-1437] DownloadLink throws TemplateModelException when target asset doesn't exist Created: 17/Oct/14 Updated: 09/Dec/16 Resolved: 08/Dec/16 |
|
| Status: | Closed |
| Project: | Magnolia Standard Templating Kit (closed) |
| Component/s: | None |
| Affects Version/s: | 2.8.4 |
| Fix Version/s: | 2.9.6, 3.0.1 |
| Type: | Bug | Priority: | Neutral |
| Reporter: | Andreas Antener | Assignee: | Ilgun Ilgun |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | support | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Template: |
|
||||||||||||
| Patch included: |
Yes
|
||||||||||||
| Acceptance criteria: |
Empty
|
||||||||||||
| Date of First Response: | |||||||||||||
| Sprint: | Basel 73 | ||||||||||||
| Story Points: | 2 | ||||||||||||
| Description |
|
DownloadLinkModel doesn't check if it actually receives a valid asset from DAMTemplatingFuncitons. If the asset doesn't exist, it wraps null inside a LegacyAssetWrapper, therefore the template produces an exception while accessing methods on the legacy wrapper. Possible fix in DownloadLinkModel (check asset before returning wrapper):
public Asset getAsset() {
final String assetIdentifier = PropertyUtil.getString(this.content, "link");
if (StringUtils.isNotBlank(assetIdentifier) && null != this.damTemplatingFunctions.getAsset(assetIdentifier)) {
return new LegacyAssetWrapper(this.damTemplatingFunctions.getAsset(assetIdentifier));
}
return null;
}
The template will then show the "link does not exists" error message as before (in Magnolia 4.5). Related to Cheers |
| Comments |
| Comment by Benny Menzel [ 02/Nov/16 ] |
|
If you do not want to touch the Java world, another way would be to edit or override the template templating-kit/components/links/downloadLink.ftl like this: [#if damfn.getAssetLink(content.link)??] [#assign link=damfn.getAssetLink(content.link)] [/#if] [#if (model?has_content && link?has_content) || cmsfn.editMode] <li class="download"> [#assign document=model.asset!] [#if link?has_content && document?has_content] <a href="${link}">${content.linkTitle!document.title} <em>(${document.fileExtension?upper_case}, ${(document.fileSize / 1024)?string("0")} ${i18n['downloadLink.kb']})</em></a> [#elseif cmsfn.editMode] <a href="javascript:alert('${i18n['link.document.resolveError']?js_string}')">${i18n['link.document.resolveError']}</a> [/#if] </li> [/#if] |