You are here

function advpoll_uninstall in Advanced Poll 8

Same name and namespace in other branches
  1. 5 advpoll.install \advpoll_uninstall()
  2. 6.3 advpoll.install \advpoll_uninstall()
  3. 6 advpoll.install \advpoll_uninstall()
  4. 6.2 advpoll.install \advpoll_uninstall()
  5. 7.3 advpoll.install \advpoll_uninstall()
  6. 7 advpoll.install \advpoll_uninstall()
  7. 7.2 advpoll.install \advpoll_uninstall()

implements hook_uninstall

File

./advpoll.install, line 9

Code

function advpoll_uninstall() {

  // clean up fields we added.
  $entity_manager = \Drupal::service('entity_field.manager');
  $fields = $entity_manager
    ->getFieldDefinitions('poll', 'poll');
  if (isset($fields['field_poll_type'])) {
    $fields['field_poll_type']
      ->delete();
  }
  if (isset($fields['field_writein'])) {
    $fields['field_writein']
      ->delete();
  }
  if (isset($fields['field_writein_multiple'])) {
    $fields['field_writein_multiple']
      ->delete();
  }
  if (isset($fields['field_number_of_votes'])) {
    $fields['field_number_of_votes']
      ->delete();
  }
  if (isset($fields['field_start_date'])) {
    $fields['field_start_date']
      ->delete();
  }

  // Clean up choice fields.
  $choiceFields = $entity_manager
    ->getFieldDefinitions('poll_choice', 'poll_choice');
  if (isset($choiceFields['field_writein'])) {
    $choiceFields['field_writein']
      ->delete();
  }
}