You are here

public function MultidomainGoogleAnalyticsAdminSettingsForm::buildForm in Multidomain Google Analytics 8.2

Same name and namespace in other branches
  1. 8 src/Form/MultidomainGoogleAnalyticsAdminSettingsForm.php \Drupal\multidomain_google_analytics\Form\MultidomainGoogleAnalyticsAdminSettingsForm::buildForm()

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 ConfigFormBase::buildForm

File

src/Form/MultidomainGoogleAnalyticsAdminSettingsForm.php, line 78

Class

MultidomainGoogleAnalyticsAdminSettingsForm
Configure Google_Analytics settings for this site.

Namespace

Drupal\multidomain_google_analytics\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $domains = $this->entityTypeManager
    ->getStorage('domain')
    ->loadMultiple();
  if ($domains) {
    $form['general'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Multidomain Google Analytics Settings'),
      '#open' => TRUE,
    ];
    $configFactory = $this
      ->config('multidomain_google_analytics.settings');
    foreach ($domains as $domain) {
      $hostname = $domain
        ->gethostname();
      if ($domain
        ->id()) {
        $form['general'][$domain
          ->id()] = [
          '#type' => 'textfield',
          '#title' => $this
            ->t('Google Analytics ID for Domain: @hostname', [
            '@hostname' => $hostname,
          ]),
          '#description' => $this
            ->t('The ID assigned by Google Analytics for this website container.'),
          '#maxlength' => 64,
          '#size' => 64,
          '#default_value' => $configFactory
            ->get($domain
            ->id()),
          '#weight' => '0',
        ];
      }
    }
    return parent::buildForm($form, $form_state);
  }
  else {
    $url = Url::fromRoute('domain.admin');
    $domain_link = Link::fromTextAndUrl($this
      ->t('Domain records'), $url);
    $form['title']['#markup'] = $this
      ->t('There is no Domain record yet.Please create a domain records.See link: @domain_list', [
      '@domain_list' => $domain_link,
    ]);
    return $form;
  }
}