public function GlobalForm::submitForm in Googalytics - Google Analytics 8
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides ConfigFormBase::submitForm
File
- modules/
ga_tokens/ src/ Form/ GlobalForm.php, line 220
Class
- GlobalForm
- Form for editing Google Analytics Global Dimensions settings.
Namespace
Drupal\ga_tokens\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$dimensions = [];
foreach ($form_state
->getValues()['dimensions'] as $index => $dimension) {
if (!empty($dimension['label']) || !empty($dimension['value'])) {
$dimensions[$index] = [
'label' => $dimension['label'],
'value' => $dimension['value'],
];
}
}
$metrics = [];
foreach ($form_state
->getValues()['metrics'] as $index => $metric) {
if (!empty($metric['label']) || !empty($metric['value'])) {
$metrics[$index] = [
'label' => $metric['label'],
'value' => $metric['value'],
];
}
}
$this
->config('ga_tokens.global')
->set('dimensions', $dimensions)
->set('metrics', $metrics)
->save();
parent::submitForm($form, $form_state);
}