You are here

protected function SettingsForm::buildZoneSelectSection in CloudFlare 8

Builds zone selection section for inclusion in the settings form.

Parameters

\Drupal\Core\Config\Config $config: The readonly configuration.

Return value

array Form Api render array with selection section.

1 call to SettingsForm::buildZoneSelectSection()
SettingsForm::buildForm in src/Form/SettingsForm.php
Form constructor.

File

src/Form/SettingsForm.php, line 217

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\cloudflare\Form

Code

protected function buildZoneSelectSection(Config $config) {
  $section = [];
  $section['zone_selection_fieldset'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Current Zone Selection'),
    '#weight' => 0,
  ];
  $zone_id = $config
    ->get('zone_id');
  if (!empty($zone_id)) {

    // Get the zones.
    $zones = [];
    if ($config
      ->get('valid_credentials') === TRUE && $this->cloudFlareComposerDependenciesMet) {
      try {
        $zones = $this->zoneApi
          ->listZones();
      } catch (CloudFlareTimeoutException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('Unable to connect to CloudFlare in order to validate credentials. Connection timed out. Please try again later.'));
      }
    }

    // Find this zone_id.
    foreach ($zones as $zone) {
      if ($zone
        ->getZoneId() == $zone_id) {
        $zone_text = $zone
          ->getName();
        break;
      }
    }
    $description = $this
      ->t('To change the current zone click the "Next" button below.');
  }
  else {
    $zone_text = $this
      ->t('No Zone Selected');
    $description = $this
      ->t('No zone has been selected.  Enter valid Api credentials then click next.');
  }
  $section['zone_selection_fieldset']['zone'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Current Zone'),
    '#description' => $description,
    '#default_value' => $zone_text,
    '#disabled' => TRUE,
  ];
  return $section;
}