comment.post_update.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. }