General developer forum

Retrieving image url from theme settings

Picture of Jay Darnell
Re: Retrieving image url from theme settings

For anyone who runs into this same issue I figured out what was missing. I needed the following function in my theme's lib.php file: (copied from the clean theme and modified with the names of the theme settings for my image uploads)

 * Serves any files associated with the theme settings.
 * @param stdClass $course
 * @param stdClass $cm
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @param array $options
 * @return bool
function theme_uswds_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
    if ($context->contextlevel == CONTEXT_SYSTEM and ($filearea === 'headerlogo' || $filearea === 'agencylogo')) {
        $theme = theme_config::load('uswds');
        // By default, theme files must be cache-able by both browsers and proxies.
        if (!array_key_exists('cacheability', $options)) {
            $options['cacheability'] = 'public';
        return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
    } else {

Some useful documentation which initially made me realize I was probably missing a function call or something of that nature:

Average of ratings: Useful (2)