You are here

public function ContentSyncSettings::getSiteBaseUrl in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Controller/ContentSyncSettings.php \Drupal\cms_content_sync\Controller\ContentSyncSettings::getSiteBaseUrl()
  2. 2.0.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 210

Class

ContentSyncSettings
Class ContentSyncSettings.

Namespace

Drupal\cms_content_sync\Controller

Code

public function getSiteBaseUrl($config_only = false) {
  if (null !== $this->siteBaseUrl) {
    return $this->siteBaseUrl;
  }

  // Check if the base_url is overwritten.
  $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;
}