You are here

public function Embed::site in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 2.0.x src/Controller/Embed.php \Drupal\cms_content_sync\Controller\Embed::site()
1 string reference to 'Embed::site'
cms_content_sync.routing.yml in ./cms_content_sync.routing.yml
cms_content_sync.routing.yml

File

src/Controller/Embed.php, line 89

Class

Embed
Class Embed provides helpers to embed Sync Core functionality into the site.

Namespace

Drupal\cms_content_sync\Controller

Code

public function site() {
  $this
    ->init(true);

  // Already registered if this exists.
  $uuid = $this->settings
    ->getSiteUuid();
  $force = empty($this->params['force']) ? null : $this->params['force'];
  if (IEmbedService::MIGRATE === $force || !Migration::useV2() && empty($force)) {
    return $this
      ->migrate();
  }
  $this->params['migrated'] = Migration::didMigrate();
  $embed = $uuid && (empty($this->params['force']) || IEmbedService::REGISTER_SITE !== $this->params['force']) ? $this->embedService
    ->siteRegistered($this->params) : $this->embedService
    ->registerSite($this->params);
  if ($uuid && empty($this->params)) {
    $step = Migration::getActiveStep();
    if (Migration::STEP_DONE !== $step) {
      $link = \Drupal::l(t('migrate now'), \Drupal\Core\Url::fromRoute('cms_content_sync_flow.migration'));
      \Drupal::messenger()
        ->addMessage(t('You have Sync Cores from our old v1 release. Support for this Sync Core will end on December 31st, 2021. Please @link.', [
        '@link' => $link,
      ]), 'warning');
    }
  }
  try {
    return $this
      ->run($embed);
  } catch (UnauthorizedException $e) {
    \Drupal::messenger()
      ->addMessage('Your registration token expired. Please try again.', 'warning');
    $url = \Drupal::request()
      ->getRequestUri();

    // Remove invalid query params so the user can try again.
    $url = explode('?', $url)[0];
    return RedirectResponse::create($url);
  }
}