public function GoogleAnalyticsReportsAdminSettingsForm::buildForm in Google Analytics Reports 8.3
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 GoogleAnalyticsReportsApiAdminSettingsForm::buildForm
File
- src/
Form/ GoogleAnalyticsReportsAdminSettingsForm.php, line 43
Class
- GoogleAnalyticsReportsAdminSettingsForm
- Implements Google Analytics Reports API Admin Settings form override.
Namespace
Drupal\google_analytics_reports\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$account = google_analytics_reports_api_gafeed();
if ($account instanceof GoogleAnalyticsReportsApiFeed && $account
->isAuthenticated()) {
$google_analytics_reports_settings = $this
->config('google_analytics_reports.settings')
->get();
$last_time = '';
if (!empty($google_analytics_reports_settings['metadata_last_time'])) {
$last_time = $google_analytics_reports_settings['metadata_last_time'];
}
$collapsed = !$last_time ? TRUE : FALSE;
$form['fields'] = [
'#type' => 'details',
'#title' => $this
->t('Import and update fields'),
'#open' => $collapsed,
];
if ($last_time) {
$form['fields']['last_time'] = [
'#type' => 'item',
'#title' => $this
->t('Google Analytics fields for Views integration'),
'#description' => $this
->t('Last import was @time.', [
'@time' => $this->dateFormatter
->format($last_time, 'custom', 'd F Y H:i'),
]),
];
$form['fields']['update'] = [
'#type' => 'submit',
'#value' => $this
->t('Check updates'),
'#submit' => [
[
GoogleAnalyticsReports::class,
'checkUpdates',
],
],
];
}
$form['fields']['settings'] = [
'#type' => 'submit',
'#value' => $this
->t('Import fields'),
'#submit' => [
[
GoogleAnalyticsReports::class,
'importFields',
],
],
];
}
return $form;
}