You are here

protected function PoolForm::syncCoreForm in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 8 src/Form/PoolForm.php \Drupal\cms_content_sync\Form\PoolForm::syncCoreForm()
  2. 2.0.x src/Form/PoolForm.php \Drupal\cms_content_sync\Form\PoolForm::syncCoreForm()

Step 2: Enter or select site ID.

Parameters

bool $collapsed:

Return value

array the form

2 calls to PoolForm::syncCoreForm()
PoolForm::form in src/Form/PoolForm.php
Gets the actual form array to be built.
PoolForm::poolForm in src/Form/PoolForm.php
Step 3: Select an existing pool or create a new one.

File

src/Form/PoolForm.php, line 370

Class

PoolForm
Form handler for the Pool add and edit forms.

Namespace

Drupal\cms_content_sync\Form

Code

protected function syncCoreForm(array $form, FormStateInterface $form_state, $collapsed = false) {

  /**
   * @var \Drupal\cms_content_sync\Entity\Pool $pool
   */
  $pool = $this->entity;
  if (Migration::alwaysUseV2()) {
    return [];
  }
  if ($collapsed) {
    $elements['backend_url'] = [
      '#type' => 'hidden',
      '#value' => $form_state
        ->getValue('backend_url') ? $form_state
        ->getValue('backend_url') : $pool
        ->getSyncCoreUrl(),
    ];
    return $elements;
  }
  $elements['headline'] = [
    '#markup' => '<br><br><h1>Step 1: Pick Sync Core</h1>' . '<div class="messages messages--status">' . $this
      ->t("The Sync Core is the central distribution service used to syndicate content between sites. If you don't have one yet, just <a href='mailto:info@cms-content-sync.io?subject=Evaluation%20Sync%20Core&body=Please%20provide%20me%20an%20evaluation%20Sync%20Core'>contact us</a>. <br>\n<br>\n<strong>Want to learn more?</strong><br>\nUse <a href='https://www.cms-content-sync.io/content-staging/'>Content Staging</a> to publish content from a private site to a public site. Pricing for Content Staging is documented <a href='https://www.cms-content-sync.io/content-sync-for-drupal/content-staging-for-drupal/'>here</a>.<br>\nUse <a href='https://www.cms-content-sync.io/content-syndication/'>Content Syndication</a> to connect many public sites to share content between them. Pricing for Content Syndication is documented <a href='https://www.cms-content-sync.io/content-sync-for-drupal/content-syndication-for-drupal/'>here</a>.\n") . '</div><br><br>',
  ];
  $default_backend_url = $this
    ->getDefaults($form_state)['backend_url'];
  $pools = Pool::getAll();
  $urls = [];
  $default_auth = null;
  foreach ($pools as $existing_pool) {
    $url = $existing_pool
      ->getSyncCoreUrl();
    $urls[$url] = Helper::obfuscateCredentials($url);
  }
  if (count($urls) && !isset($_GET['add-sync-core']) && empty($default_backend_url)) {
    $url = $pool
      ->getSyncCoreUrl();
    if ($url) {
      $urls[$url] = Helper::obfuscateCredentials($url);
    }
    $elements['backend_url'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Sync Core URL'),
      '#default_value' => $url ? $url : array_slice(array_keys($urls), 0, 1)[0],
      '#description' => $this
        ->t('The backend url can be overwritten within your environment specific settings.php file by using <i>@settings</i>.', [
        '@settings' => '$settings["cms_content_sync"]["pools"]["' . $this->configMachineName . '"]["backend_url"] = "http://cms-content-sync-example:8691/rest"',
        '@config_machine_name' => $this->configMachineName,
      ]) . '<br><a href="?add-sync-core">Add new</a>',
      '#options' => $urls,
      '#required' => true,
    ];
  }
  else {
    $elements['backend_url'] = [
      '#type' => 'url',
      '#title' => $this
        ->t('Sync Core URL'),
      '#default_value' => empty($default_backend_url) ? $pool
        ->getSyncCoreUrl() : $default_backend_url,
      '#description' => $this
        ->t('The backend url can be overwritten within your environment specific settings.php file by using <i>@settings</i>.', [
        '@settings' => '$settings["cms_content_sync"]["pools"]["' . $this->configMachineName . '"]["backend_url"] = "http://cms-content-sync-example.de:8691/rest"',
        '@config_machine_name' => $this->configMachineName,
      ]),
      '#required' => true,
    ];
  }

  // If the backend_url is set within the settings.php,
  // the form field is disabled.
  if (isset($this->backendUrl)) {
    $elements['backend_url']['#disabled'] = true;
    $elements['backend_url']['#default_value'] = $this->backendUrl;
    $elements['backend_url']['#description'] = $this
      ->t('The backend url is set within the environment specific settings.php file.');
  }
  $elements['continue'] = [
    '#prefix' => '<br><br>',
    '#type' => 'submit',
    '#submit' => [
      '::connectSyncCore',
    ],
    '#value' => $this
      ->t('Connect'),
    '#name' => 'connect',
    // '#limit_validation_errors' => [],
    '#attributes' => [
      'class' => [
        'button--primary',
      ],
    ],
    '#ajax' => [
      'callback' => '::ajaxReturn',
      'wrapper' => self::CONTAINER_ID,
      'method' => 'replace',
      'effect' => 'fade',
      'progress' => [
        'type' => 'throbber',
        'message' => 'loading settings...',
      ],
    ],
  ];
  return $elements;
}