You are here

public function DisqusCommentManager::ssoSettings in Disqus 8

Computes the full settings associated with Disqus SSO.

These need to be merged into the settings for basic Disqus integration for actual usage.

Return value

array An array of the ssoSettings.

Overrides DisqusCommentManagerInterface::ssoSettings

File

src/DisqusCommentManager.php, line 110

Class

DisqusCommentManager
It contains common functions to manage disqus_comment fields.

Namespace

Drupal\disqus

Code

public function ssoSettings() {
  $disqus['sso'] = [
    'name' => $this->configFactory
      ->get('system.site')
      ->get('name'),
    // The login window must be closed once the user logs in.
    'url' => Url::fromRoute('user.login', [], [
      'query' => [
        'destination' => Url::fromRoute('disqus.close_window')
          ->toString(),
      ],
      'absolute' => TRUE,
    ])
      ->toString(),
    // The logout link must redirect back to the original page.
    'logout' => Url::fromRoute('user.logout', [], [
      'query' => [
        'destination' => Url::fromRoute('<current>')
          ->toString(),
      ],
      'absolute' => TRUE,
    ])
      ->toString(),
    'width' => 800,
    'height' => 600,
  ];
  $managed_logo = $this->configFactory
    ->get('disqus.settings')
    ->get('advanced.sso.disqus_logo');
  $use_site_logo = $this->configFactory
    ->get('disqus.settings')
    ->get('advanced.sso.disqus_use_site_logo');
  if (!$use_site_logo && !empty($managed_logo)) {
    $disqus['sso']['button'] = $this->entityTypeManager
      ->getStorage('file')
      ->load($managed_logo)
      ->url();
  }
  elseif ($logo = theme_get_setting('logo')) {
    $url = $logo['url'];
    if (!UrlHelper::isExternal($url)) {
      $url = Url::fromUri('internal:' . $url, [
        'absolute' => TRUE,
      ])
        ->toString();
    }
    $disqus['sso']['button'] = $url;
  }
  else {
    $disqus['sso']['button'] = Url::fromUri('base://core/misc/druplicon.png', [
      'absolute' => TRUE,
    ])
      ->toString();
  }
  if ($favicon = theme_get_setting('favicon')) {
    $disqus['sso']['icon'] = $favicon['url'];
  }

  // Stick the authentication requirements and data in the settings.
  $disqus['api_key'] = $this->configFactory
    ->get('disqus.settings')
    ->get('advanced.disqus_publickey');
  $disqus['remote_auth_s3'] = $this
    ->ssoKeyEncode($this
    ->ssoUserData());
  return $disqus;
}