c::$data only returns what’s actually defined in your config files. $kirby->options() returns the complete options settings, i.e. defaults + user defined settings
This is the line where the merging happens (/kirby/kirby.php, line 171)
I tried to use this within the Settings class (by @jenstornell ), located in a plugin, but couldn’t get it to work: $kirby->option('thumbs.quality') always returns NULL … (same for kirby())
The reason for this is that the thumbs component is lazy-loaded, i.e. an instance of the component is only created when the thumb method is called. Therefore, the options are not defined before that happens. Thanks to @lukasbestle for the explanation.
class Settings {
/**
* Returns the default options for `kirby-webp`
*
* @return array
*/
public static function __callStatic($name, $args) {
// Set prefix
$prefix = 'plugin.kirby-webp.';
// Set config names and fallbacks as settings
$settings = [
// TODO: $kirby->option('thumb.quality') ?
'actions' => ['upload'],
'quality' => 90, // Desired WebP compression quality
'stripMetadata' => TRUE,
'serveConverted' => FALSE,
'serveOriginalOnFail' => TRUE,
'preferredConverters' => ['gd', 'webp', 'imagick'] // TODO: include 'thumbs.driver'
];
// If config settings exist, return the config with fallback
if(isset($settings) && array_key_exists($name, $settings)) {
return c::get($prefix . $name, $settings[$name]);
}
}
}
… and for the quality setting, I want whatever’s value is set (Kirby’s default being 90, otherwise whatever manually with c::set('thumbs.quality', $value)) - also as preferredConverter, I’d like thumbs.driver first, then webp.
So, basically calling thumb() makes these available via kirby()->option()? (And there’s really no easier way?)
As Sonja wrote, you can call kirby()->component('thumb'). There is no need to actually generate a thumb, you just need to load the thumb component. This also won’t break anything else, so it’s fine to do this.