How to get standard icon, when theme icon is not available

How to get standard icon, when theme icon is not available

by Adam Lucarz -
Number of replies: 3
Hello,

is there a function which returns the current theme icon's url and fallback to return the url of the standard icon when the theme does not support that icon?
Average of ratings: -
In reply to Adam Lucarz

Re: How to get standard icon, when theme icon is not available

by Mauno Korpelainen -

Mouse right click over (missing) icon - Properties tells usually the address, most standard icons are in sub folders of folder pix are in module folders (mod/nameofmodule/...). Copy the missing icons to custom theme folders.

You may always enable smartpix from Administration -> Miscellaneous -> Experimental

or set to theme config.php $THEME->custompix = false;

For missing admin tree icons read http://moodle.org/mod/forum/discuss.php?d=89825

In reply to Mauno Korpelainen

Re: How to get standard icon, when theme icon is not available

by Adam Lucarz -
Thank you for your answer. But I do not have problems with missing icons. I develop some modules for moodle and use for that new icons. My issue is that all themes will do not know my icons. That would not be a problem if there would be a function which fallback to the standard icons in the pix folder. I have written a helper function for me, but I would like to use an existing one because of consistency. My solution is:

static function get_icon_path($url){
global $CFG;
$result = configuration::build_icon_url($CFG->pixpath,$url);

//check if icon exists
if(!file_exists($result)){
$result = configuration::build_icon_url($CFG->wwwroot."/pix",$url);
}

return $result;
}

private static function build_icon_url($path, $url){
$result = $path;

//prefix slash check
if (!ereg('^/',$url)){
$result .= "/";
}

$result .= $url;
return $result;
}