You are here

public function SettingsForm::buildForm in CloudFlare 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/SettingsForm.php, line 153

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\cloudflare\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this->configFactory
    ->get('cloudflare.settings');
  $form = array_merge($form, $this
    ->buildApiCredentialsSection($config));
  $form = array_merge($form, $this
    ->buildZoneSelectSection($config));
  $form = array_merge($form, $this
    ->buildGeneralConfig($config));

  // Form elements are being disabled after parent::buildForm because:
  // 1: parent::buildForm creates the submit button
  // 2: we want to disable the submit button since dependencies unmet.
  if (!$this->cloudFlareComposerDependenciesMet) {
    $this
      ->messenger()
      ->addError(CloudFlareComposerDependenciesCheckInterface::ERROR_MESSAGE);
    $form['api_credentials_fieldset']['apikey']['#disabled'] = TRUE;
    $form['api_credentials_fieldset']['email']['#disabled'] = TRUE;
    $form['cloudflare_config']['client_ip_restore_enabled']['#disabled'] = TRUE;
    $form['cloudflare_config']['bypass_host']['#disabled'] = TRUE;
    $form['actions']['submit']['#disabled'] = TRUE;
  }
  return $form;
}