You are here

function google_analytics_counter_uninstall in Google Analytics Counter 8.3

Same name and namespace in other branches
  1. 7.3 google_analytics_counter.install \google_analytics_counter_uninstall()
  2. 7.2 google_analytics_counter.install \google_analytics_counter_uninstall()

Implements hook_uninstall().

File

./google_analytics_counter.install, line 125
Update, and uninstall functions for the Google Analytics Counter module.

Code

function google_analytics_counter_uninstall() {

  // Revoke the state values.
  GoogleAnalyticsCounterHelper::gacDeleteState();

  // Remove queued items from the database.
  GoogleAnalyticsCounterHelper::gacRemoveQueuedItems();

  // Uninstall the Google Analytics Counter field.
  $bundles = [
    'node',
  ];
  $fields['field_google_analytics_counter'] = [
    'entity_type' => 'node',
  ];

  // Delete the field config.
  foreach ($bundles as $bundle) {
    foreach ($fields as $field_name => $config) {
      $field = FieldConfig::loadByName($config['entity_type'], $bundle, $field_name);
      if (!empty($field)) {
        $field
          ->delete();
      }
    }
  }

  // Delete the field storage config.
  foreach ($fields as $field_name => $config) {
    $field_storage = FieldStorageConfig::loadByName($config['entity_type'], $field_name);
    if (!empty($field_storage)) {
      $field_storage
        ->delete();
    }
  }
}