You are here

protected function ContentHubSettingsForm::ensureClientNameIsSynced in Acquia Content Hub 8.2

Ensures client is in sync with the registered one on Content Hub.

Return value

string The ensured and synced client name.

Throws

\Exception

1 call to ContentHubSettingsForm::ensureClientNameIsSynced()
ContentHubSettingsForm::buildForm in src/Form/ContentHubSettingsForm.php
Form constructor.

File

src/Form/ContentHubSettingsForm.php, line 529

Class

ContentHubSettingsForm
Defines the form to configure the Content Hub connection settings.

Namespace

Drupal\acquia_contenthub\Form

Code

protected function ensureClientNameIsSynced() : string {
  $client_name = $this->settings
    ->getName();
  $uuid = $this->settings
    ->getUuid();
  foreach ($this->client
    ->getClients() as $client) {

    // If its not in-sync secretly change the values and resave the config.
    if ($client['uuid'] === $uuid && $client['name'] !== $client_name) {
      $client_name = $client['name'];
      if ($this->clientFactory
        ->getProvider() !== 'core_config') {
        $this
          ->messenger()
          ->addMessage($this
          ->t('Warning: client name is out of sync it should be %name. Please manually update your settings file.', [
          '%name' => $client_name,
        ]));
        break;
      }
      $this
        ->config('acquia_contenthub.admin_settings')
        ->set('client_name', $client_name)
        ->save();
    }
  }
  return $client_name;
}