I've been working with a preview that includes an SWF when an image is uploaded. The code would look like this (and it works great):
Inside _imagefield_widget_form function (replaces the "Filename" with an SWF)
$form[$fieldname][$delta]['description'] = array(
'#type' => 'markup',
'#value' => '<object width="400" height="400" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
<param value="sameDomain" name="allowScriptAccess"/>
<param value="http://www.pimpit3d.com/files/viewers/objectViewer-main.swf" name="movie"/>
<param value="transparent" name="wmode"/>
<param value="http://www.example.com/files/" name="base"/>
<param value="true" name="play"/>
<param value="flashvars='.$filename.'&width=400&height=400" name="FlashVars"/>
<embed width="400" height="400" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="sameDomain" flashvars="flashvars='.$filename.'&width=400&height=400" salign="tl" base="http://www.example.com/files/" name="" play="true" wmode="transparent" src="http://www.example.com/files/viewers/pre-viewer.swf" swliveconnect="default"/>
</object>'
);
However I just want to avoid changing the imagefield.module code itself (for easy upgrading in the future). So what is best practice when wishing to alter this widget function? It updates the interface after all template.php and override functions can get at it? Really need some help here :)
Comments
Comment #1
quicksketchYou can do this in a custom module by using hook_elements(). See #422436: remove description upload. for an example where we modify the description in a similar manner. The code there is for D6 but it should work with Drupal 5 just as well.
Comment #2
Fixdit commentedI'm having a bit of trouble with this following the example given, does this look right?
Many thanks for your swift response, it's greatly appreciated.
Comment #3
quicksketchYep that looks right to me at a first read. However, make sure that your module runs AFTER ImageField. Since "B" is before "I", your module is going to run first, then ImageField is going to re-add the description so it's not going to have any effect. Set the "weight" column in the "system" database table to a high number for your module then clear the Drupal caches. This should make your module run after ImageField and get the last shot at changing the element description.
I also noticed that since you're using the Drupal 5, the &$form_state parameter isn't going to exist, but that won't matter much since you don't use that parameter anyway.
Comment #4
Fixdit commentedGreat, thanks for your help. I'll push the bespoke module below the Imagefield and see how it goes.
Comment #5
quicksketchClosing after lack of activity.