[MGNLSTK-564] DAM Support does not work if I only have DMS handler Created: 13/Jan/10  Updated: 30/Sep/10  Resolved: 02/Aug/10

Status: Closed
Project: Magnolia Standard Templating Kit (closed)
Component/s: controls
Affects Version/s: 1.2
Fix Version/s: 1.3.5

Type: Bug Priority: Major
Reporter: Bozidar Ilievski Assignee: Ondrej Chytil
Resolution: Fixed Votes: 1
Labels: stk
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive singleDamHandlerFix.zip    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Date of First Response:

 Description   

I removed the "upload" handler from the damSupport, so that the Editor can only choose an image from DMS.
This is what I've done:
Templating Kit --> Site Definitions --> <my site> --> damSupport --> handlers --> upload.
I set the "enabled" property of this content node to "false".
This way, the Editor can only choose an image from DMS (she can not upload it directly).

If the DAM support is configured like this, with only one handler, the information about the image is not saved correctly.
For example:
If the name of the property that stores the image is "myImage", then when there are two handlers, after saving the image, in JCR browser I can see that there are two nodes for the image:
1. myImage = dms
2. myImageDmsUUID = 766a6d0d-4f96-45d8-a6a6-575bace65636
But with only one handler in place, all I get after saving the dialog is:
1. myImageDmsUUID = 766a6d0d-4f96-45d8-a6a6-575bace65636

Now when I test for the existence of the "myImage" property in freemarker, I get result that there is no image.



 Comments   
Comment by Ernst Bunders [ 27/Jan/10 ]

Some implications of this bug:

in info.magnolia.module.templatingkit.dam.DAMSupport
the following method (line 99) will throw an AssetNotFoundException,
because the handler can no longer be resolved.

public Asset getAsset(Content node, String nodeDataPrefix) throws
DAMException {
String handlerName = NodeDataUtil.getString(node, nodeDataPrefix);
final String path = node.getHandle() + "/" + nodeDataPrefix;
if(StringUtils.isEmpty(handlerName))

{ throw new AssetNotFoundException("No handler defined for " + path); }

final DAMHandler handler = handlers.get(handlerName);
if(handler == null)

{ throw new DAMException("No handler found with name [" + handlerName + "] for [" + path + "]"); }

return handler.getAsset(node, nodeDataPrefix);
}

And in info.magnolia.module.templatingkit.paragraphs.InternalTeaserModel

in the method findImage() (line 97) the following code will not find the image, because these properties will not be there:

for (String name : new String[]

{"image", "teaserImg"}

) {
try {
if(content.hasNodeData(name)) {
image = STKUtil.getAsset(content, name);
if(image != null)

{ return image; }

}
}
catch (RepositoryException e)

{ throw new RuntimeException(e); }

}

I'm pretty sure there are some more places in the stk where this is broken.

Comment by Ernst Bunders [ 03/Feb/10 ]

I created a fix for this bug, by extending the info.magnolia.module.templatingkit.dam.dialog.DialogDAM class (the class for the Dam dialog control), and add a dummy control with a save handler, that will make sure the missing property is set or removed, as required. It only kicks in when you have just one dam handler configured.

There are two classes:

nl.vpro.magnolia.module.images.dam.DialogDamSingleHandlerBugfix is the DamHandler extension. You probably want to rename this. Set this class as your dam handler.

nl.vpro.magnolia.module.images.dam.DamBugfixSaveHandler is the fieldSaveHandler. If you renme this, make sure you update the reference in line 45 of DialogDamSingleHandlerBugfix.

To use it set the config propery /config/modules/standard-templating-kit/controls/dam.class = nl.vpro.magnolia.module.images.dam.DialogDamSingleHandlerBugfix

If you have some questions, let me know

Comment by Ernst Bunders [ 03/Feb/10 ]

I found another symptom of this bug: In the Dialog The control configuration (things like label, description, requred) is not shown. I think what happens is that the actual control that is shown when you have one handler is a 'sub' and you can not set properties on the subs.

Should the control properties be propagated to this sub if there is only one handler?

Comment by Magnolia International [ 04/May/10 ]

Ernst, we're looking into this - thanks for the fix! Any chance you could provide the fix as a patch file ? (ie modify the current classes)

Comment by Ernst Bunders [ 10/May/10 ]

I don't think you should use this solution directly, because it turned out that stk was broken in more places if the first image property is missing: It turned out that stk teasers could no longer find the image of the target they were linking to. So Eventually i fixed this by changing the dam control class, to create an extra hidden form field for the first image property, so it is set at all times. I could send you the code, but i don't think you should use it, as it reflects my poor understanding of the whole dialog control code.

I must say the first solution came in handy though: we were adding an image property to a data structure in the datamodel, and by naming it imageMediaUUID we could actually use StkUtil.getAssetLink() with content from the data module, so that is something to consider.

Generated at Mon Feb 12 07:28:15 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.