How to create another image theme setting?

How to create another image theme setting?

autor Mariusz Mit -
Počet odpovědí: 2

Hello

I added such code in my custom theme:

    // Background image setting.
    $name = 'theme_custom/backgroundimage2';
    $title = 'backgroundimage2';
    $description = 'backgroundimage_desc';
    $setting = new admin_setting_configstoredfile($name, $title, $description, 'backgroundimage2');
    $setting->set_updatedcallback('theme_reset_all_caches');
    $page->add($setting);

Setting seems like OK, I can upload an image, the image is visible under settings tab, but when I try to echo this image using such code

$PAGE->theme->setting_file_url('backgroundimage2', 'backgroundimage2')

it shows such url //mydomainname.com/pluginfile.php/1/theme_custom/backgroundimage2/-1/test.jpg

which points to the not found file.

Průměr hodnocení: -
V odpovědi na Mariusz Mit

Re: How to create another image theme setting?

autor Davo Smith -
Obrázek: Core developers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers

Assuming you are basing your theme on theme_boost, take a look in theme/boost/lib.php at function theme_boost_pluginfile(): https://github.com/moodle/moodle/blob/master/theme/boost/lib.php#L82

This is the callback function that Moodle uses whenever a file is requested, to check that a) the file exists and b) that the current user has permission to view it.

As you should be able to see from that function, it currently only serves up files that are found in the 'logo', 'backgroundimage' or 'loginbackgroundimage' file areas - if you want users to be able to access files in another file area, then you'll need to extend the code to add it to the list.

V odpovědi na Mariusz Mit

Re: How to create another image theme setting?

autor Michael Milette -
Obrázek: Core developers Obrázek: Documentation writers Obrázek: Particularly helpful Moodlers Obrázek: Plugin developers Obrázek: Testers Obrázek: Translators
Hi Mariusz,

The easiest way to figure out how to do a particular type of theme settings is to look at the source codes in other themes.

For example, the Trema theme has a setting for you to upload carousel slide images and also a background image for the login page.

You can learn a lot and save a lot of time by simply watching how other developers have already done it.

Best regards,

Michael Milette