comment.post_update.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Post update functions for the comment module.
  5. */
  6. use Drupal\Core\Config\FileStorage;
  7. use Drupal\Core\Config\InstallStorage;
  8. /**
  9. * Enable the comment admin view.
  10. */
  11. function comment_post_update_enable_comment_admin_view() {
  12. $module_handler = \Drupal::moduleHandler();
  13. $entity_type_manager = \Drupal::entityTypeManager();
  14. // Save the comment delete action to config.
  15. $config_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
  16. $storage = new FileStorage($config_install_path);
  17. $entity_type_manager
  18. ->getStorage('action')
  19. ->create($storage->read('system.action.comment_delete_action'))
  20. ->save();
  21. // Only create if the views module is enabled.
  22. if (!$module_handler->moduleExists('views')) {
  23. return;
  24. }
  25. // Save the comment admin view to config.
  26. $optional_install_path = $module_handler->getModule('comment')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
  27. $storage = new FileStorage($optional_install_path);
  28. $entity_type_manager
  29. ->getStorage('view')
  30. ->create($storage->read('views.view.comment'))
  31. ->save();
  32. }
  33. /**
  34. * Add comment settings.
  35. */
  36. function comment_post_update_add_ip_address_setting() {
  37. $config_factory = \Drupal::configFactory();
  38. $settings = $config_factory->getEditable('comment.settings');
  39. $settings->set('log_ip_addresses', TRUE)
  40. ->save(TRUE);
  41. }