function system_update_8046

Install new default views.

Related topics

File

drupal/core/modules/system/system.install, line 1922
Install, update and uninstall functions for the system module.

Code

function system_update_8046() {
  $config_to_import = array(
    'views.view.user_admin_people' => 'user',
    'views.view.content' => 'node',
  );
  $front_page = config('system.site')
    ->get('page.front') ?: 'node';
  if ($front_page == 'node') {

    // This imports the node frontpage view.
    $config_to_import['views.view.frontpage'] = 'node';
  }
  foreach ($config_to_import as $config_name => $module) {
    $module_config_path = drupal_get_path('module', $module) . '/config';
    $module_filestorage = new FileStorage($module_config_path);
    $config_storage = drupal_container()
      ->get('config.storage');

    // If this file already exists, something in the upgrade path went
    // completely wrong and we want to know.
    if ($config_storage
      ->exists($config_name)) {
      throw new ConfigException(format_string('Default configuration file @name of @module module unexpectedly exists already before the module was installed.', array(
        '@module' => $module,
        '@name' => $config_name,
      )));
    }
    $config_storage
      ->write($config_name, $module_filestorage
      ->read($config_name));
  }
}