Uploaded image for project: 'Magnolia Standard Templating Kit (closed)'
  1. Magnolia Standard Templating Kit (closed)
  2. MGNLSTK-1437

DownloadLink throws TemplateModelException when target asset doesn't exist

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 2.9.6, 3.0.1
    • 2.8.4
    • None
    • Yes
    • Basel 73
    • 2

      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 MGNLSTK-1434 which would also be fixed with this.

      Cheers
      Andreas

        Acceptance criteria

              ilgun Ilgun Ilgun
              ada Andreas Antener
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: