Filefield CCK field formatter
stormsweeper - March 16, 2009 - 22:28
| Project: | SWF Tools |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Simply put, a CCK field formatter that maps thw SWF Tools module(s) to a filefield. Very basic module attached.
| Attachment | Size |
|---|---|
| swftff.tgz | 599 bytes |

#1
Note that if you're using Firefox 3 (like I am) this may not work correctly. See #348437: Not Visible in Firefox But Autoplay Works
#2
Also, in case this wasn't clear:
1. enable this module
2. in the field display settings for the filefield in question, select the "SWF Tools" formatter instead of the default.
#3
I'm not sure that this is necessarily related to Firefox, it is more to do with the auto size detection function failing, but that doesn't happen for me here. Might be a case of try it and see!
I'll take a quick look at the file you uploaded tomorrow - I like the idea of a "quick fix" to integrate with a filefield - makes the creation of content type really easy! There was an earlier module under SWF Tools 5 that was called "integration" but it was always flagged as unstable! This is potentially a much neater solution.
#4
It's a short module, all it does is define the formatter and the theme function, which calls swf(). Currently I have it set to also call the default filefield formatter after that, so a download link can be provided or not based on the usual "list" option for filefield. Screenshot attached.
#5
Minor update to the module, the theme function in the original one did not handle the case of a null file (i.e. no files for the node).
#6
I ran a quick test locally, and this looks like it works really well.
I'm going to suggest renaming the module from swftff to something a little more friendly (most of the SWF Tools functions are now fairly descriptive) but I'll do that locally and then roll it up in to HEAD and DRUPAL-6--2.
This is such a neat solution I can't believe I never thought of this - thanks for the contrib!
#7
Attached is an untested version of the module for D5
#8
Oh, and the name was just a quick one I knew would not cause any conflicts, feel free to change it. Just be sure to replace swftff everywhere in the module with whatever you choose.
#9
This patch is against 6.x-DEV based on stormsweeper's work. I keep it under needs work, as the SWF files aren't working correctly. (The swf works correctly with the SWF filter, but not with
swf()function).As a follow up patch we can have another formatter - 'SWF tools with no down-loadable file' (i.e. it will show only the SWF).
#10
Here's the patch with the 'SWF tools with no down-loadable file' formatter.
#11
@Amitaibu - thanks for the revised patches, but I have a couple of questions...
Not sure what you mean here? What's not working right - is it the filefield/SWF Tools element, or something more general about SWF Tools.
I see you've rolled the patches in to the main SWF Tools module - I can't decide whether that's the right way to go, or whether to have the filefield support as a separate little module. Open to thoughts on that! I can see pros and cons for both...
I need to test further, but stormsweeper was suggesting that the download link can be suppressed by setting the files "list" setting to unlisted. If that's the case then we can use just a single SWF Tools formatter to generate the content 'in addition' to whatever the filefield setting is?
Given that there are patches being produced for this proposed change so quickly I'm guessing this is a "wanted" feature, so thanks for joining in :-)
#12
1) swf() doesn't work for me regardless of the patch, I'll investigate, might be just bad configuration from my part. If this patch works for you then for sure it's my system :)
2) IMO it should be in core and not a separate module - since we are dealing with so little line of codes + so many users are already using CCK, it would probably serve most of them without the need to enable another module.
3) File list - indeed, so this patch is the same as in #9.
#13
I came to the same conclusion on my way home from work :-)
If swf() isn't working at all, can I check it you're using HEAD or DRUPAL-6--2. HEAD is unstable at the moment as I'm trying to improve the file name creation routine and I broke it - oops!
#14
Using DRUPAL-6--2 + I was able to fix it - something was wrong with my SWF file. So setting to needs review :)
#15
Guys - this is such a brilliantly simple change I can't believe I never did it before.
I have taken your respective patches and rolled them in to the main module - I agree with Amitaibu - the few lines of code are so short, and it provides a "seamless" link in to CCK.
After testing I put the "SWF Tools with link" and "SWF Tools with no link" back in. Filefield seems to give you the option to present the user with a list selection. If the list setting isn't shown the download link is always added, and if the checkbox is shown the user can choose.
So the SWF formatter behavior is that the "with link" setting will respect the check box setting, and the "no link" setting will never add a link. That seems to be the right functionality since if the admin wants the link to always be present they simply hide the checkbox from the user using the filefield setting.
I tweaked the theme definition slightly so there is one theme function, but it checks the element formatter parameter so see whether to include the link or not. That makes the code slightly simpler.
I tested locally, and it works great. Add the file field, apply the SWF Tools formatter, and you have swf/audio/video up and running. That's what I call a low maintenance solution!
The code is in HEAD and DRUPAL-6--2 now if you don't mind testing it, and then it can be released.
I'm about to go on vacation so it might be few days before I get access to do it. (Much as I'd love to spend my holiday coding on balance I'd rather go to the beach with my daughter!)
Thanks again for the patches!!
--edit
One thought - if you look at theme_filefield_formatter_default() it in turn calls theme_filefield_item() which actually does a check to see if you have permission to view the content. I wonder if that should be included in the swf formatter so that users who aren't allowed to see the content can't? It's too late here for me to think that one through...
--/edit
#16
I'm able to see it working on public file system, but for some reason it doesn't show the SWF on private file system. any idea why?
#17
Can you post a code sample from the page in question so we can check how the path is made.
Also, check if you are able to download the file with the download link. If the download doesn't work either then the issue is that nothing is granting permission on the file for access.
#18
Yes, that most likely is some issue with your settings either for filefield or your hosting account.
#19
Stuart, this is all you would need to add for the CCK permissions:
<?phpif (!filefield_view_access($element['#field_name'])) {
return '<!-- you do not have access to view this file -->';
}
// rest of theme function
?>
#20
@Amitaibu
I should engage my brain. This is a known issue in filefield - and I should know because I reported it in #325795: Content-Disposition: attachment breaks swf content.
There's a description, and now a patch, on that thread. The issue is that filefield sets
Content-Disposition: attachmentand flash doesn't like that. Although the thread is marked as fixed the code isn't in the 6.x-3.0-beta2 release and you have to fix it yourself. I'm guessing / hoping that the fix will make the final release of filefield!#21
Hi guys! I just hopped into the SWF Tools thread to make this exact same request. Glad to see you guys got here before me! I've given several presentations and recommendations about using FileField with SWF Tools, and this was the one hang-up where I kept loosing people. Fantastic to see it already included in SWF Tools. Much to my pleasure, I'm now maintaining FileField, if you need anything, just post an issue. I've already posted SWF Tools to the list of recommended modules to use with conjunction with FileField.
Stuart: I really thought that issue was resolved with private downloads. As you can see in the patch, FileField is now explicitly setting the disposition to "inline" instead of "attachment". If it's not working, please reopen that issue and I'll gladly accept anything you suggest to fix the problem.
Great work, though. I'm thrilled to see this in SWF Tools.
#22
@Stuart Greenfield,
I remembered I saw this issue in the CVS, but couldn't find it. thanks for the pointer, I'll check it later.
Just an FYI, I saw this module yesterday and tried the do the same thing there - #407724: SWFembed filefield formatter for SWF files
#23
@Stuart Greenfield,
Using fileifeld DEV version fixed the problem - thanks :) Maybe a better title for the formatters should be:
* SWF tools - download link configured by fileifeld's 'list field' option
* SWF tools - override filefield's 'list field' option and never show the download link
#24
Actaully, Private download still doesn't work. If I try to swf() a file that was uploaded manually and 'Allow SWF Tools to grant access to supported private files' is checked it works properly, however files that were uploaded via filefield, don't show up.
#25
Have a look at the flashfileformatter in cck_formatters, too. It uses swfobject_api internally to format anything uploaded into a filefield as flash, or an image.
There's also an open issue to add the same functionality to the new swfembed module (#407724: SWFembed filefield formatter for SWF files).
#26
In response to #24, it sounds like something is denying access. If i remember rightly then if any one module denies access to a file then access isn't given, even if all other modules said "go ahead!".
I'm on vacation so I'll follow up the rest of this thread when i get back.
#27
Thanks for rolling in the CCK field formatter in 3/19 -dev. It's peachy! Hope it'll be in stable release ('head'?? not sure of the terminology here) soon.
#28
Attached is a tested D5 module. Just throw it into a folder with an .info file and enable it, and you'll see "SWF Tools" as a formatter option. The original posted in #7 had a few typos.
#29
@SamLerner - brilliant - thanks for that. Will take a look shortly and roll in to SWF Tools 5.
@eoneillPPH - this will be out shortly (hopefully next week). Glad you like the feature - like all the best things - simple and elegant :-)
#30
Fixed in release 6.x-2.4.
Not yet rolled in to SWF Tools 5.
#31
This is a fantastic addition to an incredibly useful module. Thanks for all the hard work.
Quick related question: is there a way for multiple filefield uploads to be rolled automatically into a playlist?
For instance, I'd love to be able to upload several images via filefield and have them show up as a single playlist in the JW image rotator.
Thanks,
Brett
#32
There is now - I added it tonight, and it's on branch DRUPAL-6--2, and it should be picked up in to the 6.x-2.x development release if you'd like to test it! I have tried it locally with audio and images, and it's working great. Look for a development release dated after March 30 to make sure you get a package that includes it.
When you've downloaded it run update.php to pick up the new theme function, and then on CCK you'll find you have a third SWF Tools formatter - SWF Tools - playlist. Choose that formatter, upload your files, and that's it.
I thought this would be a five minute job but it took me all night to work out how to get the file elements out of CCK!!
I think these new CCK features could prove to be VERY useful since it makes it incredibly easy to create single media and playlists/galleries.
#33
Thanks so much, Stuart ... I'll give it a go and let you know if I run into any problems.
#34
How exactly does this differ from the flashfileformatter in the cck_formatters module?
#35
@Crell
This just passes in the filefield path to the swf() function. Essentially, I made a formatter to do what had previously been shown as a theming layer solution:
http://mustardseedmedia.com/podcast/episode17
So it works for any file type swftools can handle, but my intent was to make a quick and easy audio player field without having to muck about at the theme level. So with this set on a filefield, any mp3 files or whatever would be replaced by the configured media player.
#36
Also, if you upload an audio or video file these will be displayed in the configured SWF Tools player.
The flash content will be displayed using the currently configured SWF Tools embedding method, where as the other formatter only uses SWFObject_API.
#37
Is this included in 6.x-2.5? or do I need to download this module and enable it in order to get this feature?
#38
This is included in 6.x-2.5.
No need to download/install this separate module.
Thnx.
#39
Marking as fixed, since this has been in 6.x for some time now. Not sure about 5.x.
#40
Thanks for this - a great solution to a problem I've been grappling with for some time now! However, I'm not able to get this to work. I'm using SWF Tools 6.x-2.5, but in CCK when selecting "File" as the data type, I'm only seeing "File Upload" and "Image" as my options for the form element. Is there something else I need to enable to get the SWF Formatter on my options list?
Thanks!
#41
Disregard #40, I found the answer here: http://drupal.org/node/486838.
#42
Automatically closed -- issue fixed for 2 weeks with no activity.
#43
I'm sorry if I'm posting prematurely, but have studied things as carefully as I can and still cannot get this to work. After assigning the filefield filter, uploading several files and submitting the page, I only get the first file to play. The playlist appears ok when viewed. The mp3 files all seem to be present, both in the fields on the page and in the default/files directory. The player (JW Player 4 in this case) is set to auto-play, appears and plays without any error I can see, but simply stops after the first file, without a forward button to advance to another file. Various embedding settings and other players seem to have the same results.
In case there is any relation, as an ulternative, when entering
<swf files="file1.mp3&&file2.mp3">method in the body , again the first file plays, then an error for each successive file appears, "Flash player cannot display because the file amp does not exist." I take it that has to do with the double ampersands, but after checking the filters and weights I'm not sure what else might be wrong. Forgive me if this is an obvious oversight on my part. I'm trying to read and study carefully, but I am a newby. Thank you very much.