You are here

public function GoogleAnalyticsAdminSettingsForm::removeCallback in Google Analytics 4.x

Submit handler for the "remove one" button.

Decrements the max counter and causes a form rebuild.

File

src/Form/GoogleAnalyticsAdminSettingsForm.php, line 1171

Class

GoogleAnalyticsAdminSettingsForm
Configure Google_Analytics settings for this site.

Namespace

Drupal\google_analytics\Form

Code

public function removeCallback(array &$form, FormStateInterface $form_state) {
  $removed_trigger = $form_state
    ->getTriggeringElement();
  $gtag_id = substr($removed_trigger['#name'], strlen('remove_gtags_ids'));
  $removed_ids = $form_state
    ->get('remove_ids') ?? [];
  $removed_ids[] = $gtag_id;
  $form_state
    ->set('remove_ids', $removed_ids);

  // Since our buildForm() method relies on the value of 'num_names' to
  // generate 'name' form elements, we have to tell the form to rebuild. If we
  // don't do this, the form builder will not call buildForm().
  $form_state
    ->setRebuild();
}