You are here

public function DeveloperSyncForm::buildForm in Apigee Edge 8

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/DeveloperSyncForm.php, line 69

Class

DeveloperSyncForm
Provides a form to start developer synchronization.

Namespace

Drupal\apigee_edge\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  try {
    $this->sdkConnector
      ->testConnection();
  } catch (\Exception $exception) {
    $this
      ->messenger()
      ->addError($this
      ->t('Cannot connect to Apigee Edge server. Please ensure that <a href=":link">Apigee Edge connection settings</a> are correct.', [
      ':link' => Url::fromRoute('apigee_edge.settings')
        ->toString(),
    ]));
    return $form;
  }
  $form['#attached']['library'][] = 'apigee_edge/apigee_edge.admin';
  $form['sync'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Synchronize developers'),
    '#open' => TRUE,
  ];
  $form['sync']['description'] = [
    '#type' => 'container',
    'p1' => [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this
        ->t('Developer synchronization will:'),
    ],
    'list' => [
      '#theme' => 'item_list',
      '#items' => [
        $this
          ->t('Create Drupal users for any Apigee Edge developers that are in this Drupal system'),
        $this
          ->t('Create developers in Apigee Edge for all users in this Drupal system that are not already in Apigee Edge'),
      ],
    ],
    'p2' => [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this
        ->t('Note that any Drupal users that are created will have a random password generated and will need to reset their password to log in. The "Run developer sync" button will sync the developers, displaying a progress bar on the screen while running. The "Background developer sync" button will run the developer sync process in batches each time <a href=":cron_url">cron</a> runs and may take multiple cron runs to complete.', [
        ':cron_url' => Url::fromRoute('system.cron_settings')
          ->toString(),
      ]),
    ],
  ];
  $form['sync']['sync_submit'] = [
    '#title' => $this
      ->t('Run developer sync'),
    '#type' => 'link',
    '#url' => $this
      ->buildUrl('apigee_edge.developer_sync.run'),
    '#attributes' => [
      'class' => [
        'button',
        'button--primary',
      ],
    ],
  ];
  $form['sync']['background_sync_submit'] = [
    '#title' => $this
      ->t('Background developer sync'),
    '#type' => 'link',
    '#url' => $this
      ->buildUrl('apigee_edge.developer_sync.schedule'),
    '#attributes' => [
      'class' => [
        'button',
      ],
    ],
  ];
  return $form;
}