You are here

public function MigrationForm::buildForm in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 2.0.x src/Form/MigrationForm.php \Drupal\cms_content_sync\Form\MigrationForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/MigrationForm.php, line 28

Class

MigrationForm
Content Sync general settings form.

Namespace

Drupal\cms_content_sync\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // TODO: Drupal: Recreate Content Sync user password during migration to use stronger 64 characters and also ensure that the old Sync Core can't push updates anylonger; so this must be the last step when switching over.
  $settings = ContentSyncSettings::getInstance();

  // Already registered if this exists.
  $uuid = $settings
    ->getSiteUuid();
  if ($uuid) {

    //$form['#prefix'] = '<div style="display: none;">';

    //$form['#suffix'] = '</div>';
    $form['#attributes']['style'][] = 'display: none;';
    $all_pools = Pool::getAll();
    $pool_options = [];
    foreach ($all_pools as $pool) {
      $pool_options[$pool
        ->id()] = $pool
        ->label();
    }
    $form['export-pools'] = [
      '#prefix' => '<div id="content-sync-migration-export-pools">',
      '#suffix' => '</div>',
      '#title' => 'Export pools',
      '#type' => 'checkboxes',
      '#options' => $pool_options,
    ];
    $all_flows = Flow::getAll();
    $flow_options = [];
    foreach ($all_flows as $flow) {
      $flow_options[$flow
        ->id()] = $flow
        ->label();
    }
    $form['export-flows'] = [
      '#prefix' => '<div id="content-sync-migration-export-flows">',
      '#suffix' => '</div>',
      '#title' => 'Export flows',
      '#type' => 'checkboxes',
      '#options' => $flow_options,
    ];
    $form['skip-flows-test'] = [
      '#prefix' => '<div id="content-sync-migration-skip-flows-test">',
      '#suffix' => '</div>',
      '#title' => 'Skip flows test',
      '#type' => 'checkboxes',
      '#options' => $flow_options,
    ];
    $form['skip-flows-push'] = [
      '#prefix' => '<div id="content-sync-migration-skip-flows-push">',
      '#suffix' => '</div>',
      '#title' => 'Skip flows migration',
      '#type' => 'checkboxes',
      '#options' => $flow_options,
    ];
    $form['skip-flows-pull'] = [
      '#prefix' => '<div id="content-sync-migration-skip-flows-pull">',
      '#suffix' => '</div>',
      '#title' => 'Skip flows migration',
      '#type' => 'checkboxes',
      '#options' => $flow_options,
    ];
    $form['action'] = [
      '#title' => 'Action',
      '#type' => 'radios',
      '#options' => [
        'export-pools' => 'Export Pools',
        'export-flows' => 'Export Flows',
        'skip-flows-test' => 'Skip Flows test',
        'skip-flows-push' => 'Skip Flows push',
        'skip-flows-pull' => 'Skip Flows pull',
        'switch' => 'Switch',
      ],
    ];
    $form['submit'] = [
      '#type' => 'submit',
      '#value' => 'Submit',
      '#button_type' => 'primary',
    ];
  }
  else {
    $url = Url::fromRoute('cms_content_sync_flow.site')
      ->toString();
    \Drupal::messenger()
      ->addMessage('Please register this site first.', 'warning');
    $form['redirect'] = [
      '#markup' => 'This site is not registered yet. Please <a href="' . $url
        ->toString() . '">register first</a>.',
    ];
  }
  return $form;
}