public function ContentSyncSettings::getSiteBaseUrl in CMS Content Sync 2.0.x
Same name and namespace in other branches
- 8 src/Controller/ContentSyncSettings.php \Drupal\cms_content_sync\Controller\ContentSyncSettings::getSiteBaseUrl()
- 2.1.x src/Controller/ContentSyncSettings.php \Drupal\cms_content_sync\Controller\ContentSyncSettings::getSiteBaseUrl()
Parameters
bool $config_only: Whether to return the base URL as per the settings only. Otherwise it will return the default site URL.
Return value
string
Throws
\Exception
File
- src/
Controller/ ContentSyncSettings.php, line 220
Class
- ContentSyncSettings
- Class ContentSyncSettings.
Namespace
Drupal\cms_content_sync\ControllerCode
public function getSiteBaseUrl($config_only = false) {
if (null !== $this->siteBaseUrl) {
return $this->siteBaseUrl;
}
// Allow overwritting of the base_url from the global $settings.
$setting = Settings::get('cms_content_sync_base_url', \Drupal::state()
->get('cms_content_sync.base_url'));
if ($config_only) {
return $setting;
}
if ($setting) {
// Validate the Base URL.
if (UrlHelper::isValid($setting, true) && '/' !== mb_substr($setting, -1)) {
return $this->siteBaseUrl = $setting;
}
throw new \Exception(t('The configured base URL is not a valid URL. Ensure that it does not contain a trailing slash.'));
}
global $base_url;
return $this->siteBaseUrl = $base_url;
}