After installing FileField 5.x-2.3-rc2, creating an ico directory and uploading several __.png files I still didn't see any icons.
Looking into the code of filefield.module (716-721) I found:
$icon = '';
$iconpath = base_path() .'/'. drupal_get_path('module','filefield') .'/ico/'. $ext .'.png';
if (file_exists($iconpath)) {
$icon = '<img class="field-icon-'. $ext .'" src="'. $imagepath .'" />';
}
return '<div class="filefield-icon field-icon-'. $ext .'">'. $icon .'</div>';
The trouble seems to be that $imagepath isn't defined (it seems to be $iconpath), there is a .'/'. too many and the "file_exists" can be problematic on a safe_mode PHP install.
I could make the icons work again by replacing the code above by the following:
$icon = '';
$iconpath = base_path() . drupal_get_path('module','filefield') .'/ico/'. $ext .'.png';
if (!$size=@getimagesize($iconpath)) {
$icon = '<img class="field-icon-'. $ext .'" src="'. $iconpath .'" />';
}
return '<div class="filefield-icon field-icon-'. $ext .'">'. $icon .'</div>';
In order be able to see the icons I also had to remove the div.filefield-icon definition from the filefield.css.
Now the icons are visible again while editing nodes and pasting the code from #196957: Add icons to default filefield formatters. into your template.php will make the icons show up while viewing nodes as well.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | filefield.icon_.patch.txt | 705 bytes | robin van emden |
Comments
Comment #1
jpetso commentedIt doesn't hurt to have a '/' too many, but it hurts when it's missing. I believe I inserted the slash in response to a bug report, because we can't rely on base_path() ending with a slash or drupal_get_path() starting with one.
Other than that, the change seems sensible to me. Please post the change (without slash removal) as a patch file, plus I'd like to know if dopry is ok with getimagesize().
Comment #2
robin van emden commentedWill post a patch file tomorrow, thank you for your quick reply! As a matter of fact I did have some trouble with a double slash at the start of the $iconpath string on a windows testing server.
I thought this might be because of the default behavior of file_exists (see http://us.php.net/file_exists):
If the getimagesize() solution is decided to be ok that might also solve this particular issue?
Comment #3
jpetso commentedBah, those frickin' edge cases. In that case, I'd like to think that an
rtrim(base_path())should be sufficient for both the Windows network syntax and the case where base_path() doesn't return a trailing slash. Could you try if that works for you?Comment #4
robin van emden commentedPatch, haven't had time yet to test rtrim(base_path()), so for now it's based on my original code.
Comment #5
dopry commentedThis should be fixed in the latest 5.x-2.x dev branch.
Comment #6
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.