Hi,
I'm in the midst of configuring our site to use Scald, and I wanted to customize the captions displayed underneath the images. I ended up modifying scald.tokens.inc to look for any entity text field attached to the scald atom, and offering those up as potential tokens to be used to populate the caption field. I'm not strongly familiar with your code base, so I don't know if you've a better way to do something like this, but I wanted to share a patch in case you thought it might be useful to others.
Example use:
1. Hang a text field on image atoms (admin/structure/scald/image/fields) called field_caption.
2. Configure a context to use the html5 player (scald/image/player/[context name]/image_figure)
3. Change the value of "Text pattern used for caption" to [atom:field_caption].
4. Add caption values to your nodes. When they are rendered in that context, they should now use new the caption field.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | scald-custom_caption_field-2218205-14.patch | 1.95 KB | alex.bukach |
| #4 | scald-custom-caption-field-2218205-4.patch | 3.03 KB | aron.beal |
| #1 | scald-Custom_caption_field-2218205-1.patch | 1.42 KB | aron.beal |
Comments
Comment #1
aron.beal commentedComment #2
jcisio commentedScald does not want to fully support Token integration. If you want it, you can use the Entity Token module (in the Entity API project) and will have all fields available as token in the Atom player.
Comment #3
aron.beal commentedCan you expand on that a bit? I've got entity token enabled for a separate reason already, and yet, when I enter the value of [atom:field_caption] as a token value in the "Text pattern used for caption" field for the html5 image player settings, it simply displays the token text. It *does* work properly with a value of [atom:title], however.
Comment #4
aron.beal commentedI do see a couple of default tokens you have defined in scald.tokens.inc. I wanted to run another patch past you (scald-custom-caption-field-2218205-4.patch). This one makes scald query the active scald atom types as part of the token discovery process, and makes available the tokens for all attached entity fields of type text. It also shows those tokens in the player form configuration (only for image types with this patch).
Comment #5
alex.bukach commentedIn fact we cannot use Entity Tokens module, since it makes replacements based on entity name which is
scald_atomin the case, while scald module passes atom asatom. To make it work (and keep it consistent) we should pass atom withscald_atomkey.Definitely we should use
[scald_atom:field_caption]in player settings after applying this patch.Comment #7
gifad commentedNow, if
, and you can write a patch, you can also write a module (it's easier !)
I use this code for years, without trouble
Hope this helps...
Comment #8
alex.bukach commentedgifad,
I completely agree with this approach: why to duplicate functionality provided by another module. However due to the reason explained in #5, the statement I've just cited is currently wrong and the module should be fixed respectively, to make the citation true.
As for writing own module, I believe having the original module fixed is more proper approach than creating such a "crutch" in each project where I need Scald.
As for the patch, I forgot about back-compatibility. Here's corrected patch.
Comment #9
alex.bukach commentedComment #10
gifad commentedAlex Bukach, I agree with you about the approach, my suggestion was just a quick and dirty workaround (keywords: quick, work), just in case "scald does not want to..."
Now, about your patch :
The compatibility issue is fixed for the settings entered with the original scald package;
But other contributed player modules will have to update all "token_replace()" calls..
This probably means a "Change record", and that's perhaps what "scald does not want to..."
Also, with Entity Tokens installed,
[scald_atom:field_caption]still does not work : one must use[scald_atom:field-caption](note the different hyphen)Go explain the user which token works and which does not...
[About my "crutch", one need to check
if (isset($atom->{$name}[$language][0]))in case a field is allowed to be empty - Nobody's perfect..]Comment #11
alex.bukach commentedgifad, I agree, custom module is good as a quick workaround, but why not to make it work properly when it's possible? I suspect not everybody using Scald is able to write a module. :)
First, the patch does not break anything for other modules providing players. Simply they will still not support tokens provided by Entity Token module, but nothing is broken. We'll have to provide respective patches for each of them once we need this support from them, that's it.
Second, right, we have to use
[scald_atom:field-caption], but anyway it's much easier than writing own module, and having some option is better than having none.Thus, the patch (1) breaks nothing and (2) provides a simple way to use tokens for fields. Do I miss anything why it should not be committed?
Comment #12
gifad commentedIf it ain't broken, why do you fix
in scald_image.module ? (2218205-8.patch, lines 9,10)
I have the very same line in my module, and it IS broken, until I apply the same fix (same for all token_replace() using scald provided tokens).
I'm using drupal 7.34, scald 7x.1.3 or scald 7x.1.3+1-dev, token 7.x-1.5, with or without my "crutch", Entity tokens module enabled or not.
The offending token being [atom:title] or [scald_atom:title]
And yes, I flush all caches before each test.
Comment #13
alex.bukach commentedgifad, what is your module?
Comment #14
alex.bukach commentedgifad, nevermind, you are right. Finally got your point.
What would you say about this patch?
Comment #15
alex.bukach commentedComment #16
alex.bukach commentedComment #17
gifad commentedHi Alex,
#14 is quite correct on the compatibilty side;
I just have to patch a
$element['view']['token_help']['help']in my player's settings to have the "Atoms" fieldset showing, but this is minor (not blocking)[quote: "gifad, what is your module ?" - It's a very standard scald image player, which just manages custom (site specific) "options" of the AtomProperties dialog - BTW, that's very easy (and safe) to implement with the new widget plugin !]
Comment #18
alex.bukach commentedGifad, what player's
$element['view']['token_help']['help']are you talking about? Your custom one?Also, what do you mean by "the new widget plugin"?
Comment #19
gifad commented@Alex
The element is part of standard way to show "Replacement patterns" from Token module;
You have a sample implementation in aron.beal's patch #4
The new widget plugin is the one introduced in Scald 7.x-1.3+1-dev
Worth a tour !
Regards
Comment #20
DrCord commentedThanks gifad. #7 works great.
Comment #21
marcoka commentedsample code from #7 is great. works. thank you for this.