You are here

function hashtags_uninstall in Hashtags 8

Same name and namespace in other branches
  1. 6.2 hashtags.install \hashtags_uninstall()
  2. 6 hashtags.install \hashtags_uninstall()
  3. 7.2 hashtags.install \hashtags_uninstall()
  4. 7 hashtags.install \hashtags_uninstall()

Implements hook_uninstall().

File

./hashtags.install, line 26

Code

function hashtags_uninstall() {
  $hashtags_field_name = \Drupal::config('hashtags.settings')
    ->get('hashtags_taxonomy_terms_field_name');
  $entity_types = _hashtags_get_content_entity_types();
  foreach ($entity_types as $entity_type) {
    $bundles = \Drupal::service('entity.manager')
      ->getBundleInfo($entity_type);
    foreach ($bundles as $bundle => $bundle_info) {
      if (_hashtags_is_field_exists($entity_type, $bundle, $hashtags_field_name)) {
        $hashtags_field = FieldConfig::loadByName($entity_type, $bundle, $hashtags_field_name);
        if (!empty($hashtags_field)) {
          $hashtags_field
            ->delete();
        }
        $activated_text_fields = _hashtags_get_activated_text_fields($entity_type, $bundle);
        foreach ($activated_text_fields as $field_name) {
          $text_field = \Drupal::entityTypeManager()
            ->getStorage('field_config')
            ->load("{$entity_type}.{$bundle}.{$field_name}");
          if (!empty($text_field)) {
            $text_field
              ->unsetThirdPartySetting('hashtags', 'hashtags_activate');
            $text_field
              ->save();
          }
        }
      }
    }
  }
}