You are here

public function FormAssemblyEntitySettingsForm::buildForm in FormAssembly 8

Defines the settings form for FormAssembly Form entities.

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 Form definition array.

Overrides FormInterface::buildForm

File

src/Form/FormAssemblyEntitySettingsForm.php, line 149

Class

FormAssemblyEntitySettingsForm
FormAssembly entity settings form.

Namespace

Drupal\formassembly\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = [];
  $form['credentials'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Oauth Credentials'),
    'provider' => [
      '#type' => 'hidden',
      '#value' => 'formassembly',
    ],
  ];
  $credentials = $this->formassemblyConfig
    ->get('credentials');
  $form['credentials']['cid'] = [
    '#type' => 'textfield',
    '#required' => FALSE,
    '#title' => t('FormAssembly OAuth Client ID'),
    '#description' => t('The client ID.'),
    '#default_value' => isset($credentials['data']['cid']) ? $credentials['data']['cid'] : '',
  ];
  $form['credentials']['secret'] = [
    '#type' => 'textfield',
    '#required' => FALSE,
    '#title' => t('FormAssembly OAuth Client Secret'),
    '#description' => t('The client secret.'),
    '#default_value' => isset($credentials['data']['secret']) ? $credentials['data']['secret'] : '',
  ];
  if ($this->keyService
    ->additionalProviders()) {
    $this
      ->buildProviderOptions($form);
  }
  $form['endpoint'] = [
    '#type' => 'url',
    '#title' => t('FormAssembly Url'),
    '#required' => TRUE,
    '#description' => t('The url of your instance. Examples: https://developer.formassembly.com, https://app.formassembly.com, https://instance_name.tfaforms.net, https://your_server/path/to/formassembly'),
    '#default_value' => $this->formassemblyConfig
      ->get('endpoint'),
  ];
  $form['admin_index'] = [
    '#type' => 'checkbox',
    '#required' => FALSE,
    '#title' => t('Admin Index'),
    '#description' => t('Return a list of all forms in the FormAssembly instance. Only applies to Enterprise level instances. The authentication tokens entered above must be from an admin-level user'),
    '#default_value' => $this->formassemblyConfig
      ->get('admin_index'),
  ];
  $documentation = Url::fromUri('http://docs.drush.org/en/master/cron/');
  $form['batch_sync'] = [
    '#type' => 'checkbox',
    '#title' => t('Sync now'),
    '#description' => t('Sync forms after submitting this form. <em>Disabled if authorization is not complete.</em>'),
    '#default_value' => FALSE,
    '#disabled' => !$this->authorize
      ->isAuthorized(),
    '#suffix' => '<div>' . t('To sync on cron, place the drush command %command into your crontab.  See @url for more information.', [
      '%command' => 'drush fa-sync',
      '@url' => $this->linkGenerator
        ->generate('Running Drupal cron tasks from Drush', $documentation),
    ]) . '</div>',
  ];
  $form['reauthorize'] = [
    '#type' => 'checkbox',
    '#title' => t('Reauthorize'),
    '#description' => t('Reauthorize this application and get a new access token.'),
    '#default_value' => FALSE,
  ];
  $form['save'] = [
    '#type' => 'submit',
    '#value' => t('Submit'),
  ];
  return $form;
}