You are here

public function ZoneSelectionForm::__construct in CloudFlare 8

Constructs a new ZoneSelectionForm.

Parameters

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The factory for configuration objects.

\Drupal\cloudflare\CloudFlareZoneInterface $zone_api: ZoneApi instance for accessing api.

\Psr\Log\LoggerInterface $logger: A logger instance.

bool $composer_dependencies_met: Checks that the composer dependencies for CloudFlare are met.

File

src/Form/ZoneSelectionForm.php, line 95

Class

ZoneSelectionForm
Class ZoneSelectionForm.

Namespace

Drupal\cloudflare\Form

Code

public function __construct(ConfigFactoryInterface $config_factory, CloudFlareZoneInterface $zone_api, LoggerInterface $logger, $composer_dependencies_met) {
  $this->configFactory = $config_factory;
  $this->config = $config_factory
    ->getEditable('cloudflare.settings');
  $this->zoneApi = $zone_api;
  $this->logger = $logger;
  $this->cloudFlareComposerDependenciesMet = $composer_dependencies_met;
  $this->hasZoneId = !empty($this->config
    ->get('zone_id'));
  $this->hasValidCredentials = $this->config
    ->get('valid_credentials') === TRUE;

  // This test should be unnecessary since this form should only ever be
  // reached when the 2 conditions are met. It's being done from an abundance
  // of caution.
  if ($this->hasValidCredentials && $this->cloudFlareComposerDependenciesMet) {
    try {
      $this->zones = $this->zoneApi
        ->listZones();
      $this->hasMultipleZones = count($this->zones) > 1;
    } catch (CloudFlareTimeoutException $e) {
      $this
        ->messenger()
        ->addError($this
        ->t('Unable to connect to CloudFlare. You will not be able to change the selected Zone.'));
    }
  }
}