5 * Post update functions for the Database Logging module.
8 use Drupal\Core\Config\FileStorage;
9 use Drupal\Core\Config\InstallStorage;
10 use Drupal\views\Entity\View;
13 * Replace 'Recent log messages' with a view.
15 function dblog_post_update_convert_recent_messages_to_view() {
16 // Only create if the views module is enabled and the watchdog view doesn't
18 if (\Drupal::moduleHandler()->moduleExists('views')) {
19 if (!View::load('watchdog')) {
20 // Save the watchdog view to config.
21 $module_handler = \Drupal::moduleHandler();
22 $optional_install_path = $module_handler->getModule('dblog')->getPath() . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
23 $storage = new FileStorage($optional_install_path);
25 \Drupal::entityTypeManager()
27 ->create($storage->read('views.view.watchdog'))
30 return t('The watchdog view has been created.');
33 return t("The watchdog view already exists and was not replaced. To replace the 'Recent log messages' with a view, rename the watchdog view and uninstall and install the 'Database Log' module");