public function MultidomainGoogleAnalyticsAdminSettingsForm::buildForm in Multidomain Google Analytics 8
Same name and namespace in other branches
- 8.2 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 77
Class
- MultidomainGoogleAnalyticsAdminSettingsForm
- Configure Google_Analytics settings for this site.
Namespace
Drupal\multidomain_google_analytics\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$domains = $this->domainLoader
->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 = $this
->l($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;
}
}