Site settings
A custom site setting added at the global level is inherited by admin-defined sites, but the setting can be changed only in the global site. When you add a custom setting, you have the option of making the setting available on admin-defined sites as well as the global site. This gives an administrator the ability to override the global setting with a site-specific setting. For example, different sites could have different support contacts; therefore, it makes sense to give site administrators the ability to override the global support setting.
To make site setting fields appear in the UI for all sites (not just Global), specify the target of the modification to SiteSettings.
public class SupportSettings extends Modification<SiteSettings>
To retrieve a site setting, call the SiteSettings#get
method, which returns the setting for a specified site, with a fallback to the Global site if the specified site is null
. For example, continuing with the SupportSettings
code example, the following statement passes the site to SiteSettings#get
, as well as the SupportSettings#getUser
method. The method is passed as a Function
object.
return SiteSettings.get(site, item -> item.as(SupportSettings.class).getUser());
If site
is not equal to null
, then the setting from the admin-defined site is retrieved; otherwise, the method falls back to the Global setting for user
.