You are here

function comment_notify_update_8002 in Comment Notify 8

Preserve node notification settings.

File

./comment_notify.install, line 103
Comment_notify.install.

Code

function comment_notify_update_8002() {
  $node_values = \Drupal::config('comment_notify.settings')
    ->get('node_types');
  $bundle_types = [];
  $field_manager = \Drupal::service('entity_field.manager');
  $bundles_with_comment_fields = [];
  $comment_field_map = $field_manager
    ->getFieldMapByFieldType('comment');
  foreach ($comment_field_map as $entity_type => $comment_fields) {
    foreach ($comment_fields as $field_name => $field_info) {
      foreach ($field_info['bundles'] as $field_bundle) {
        $bundles_with_comment_fields[$field_bundle][] = $field_name;
      }
    }
  }
  foreach ($bundles_with_comment_fields as $bundle => $fields) {
    if (!in_array($bundle, $node_values)) {
      continue;
    }
    foreach ($fields as $field_name) {
      $bundle_types[] = 'node--' . $bundle . '--' . $field_name;
    }
  }
  \Drupal::configFactory()
    ->getEditable('comment_notify.settings')
    ->set('bundle_types', $bundle_types)
    ->save();
}