You are here

function login_history_update_8002 in Login History 8

Creates the new default login_history view.

File

./login_history.install, line 82
Install, update and uninstall functions for the Login History module.

Code

function login_history_update_8002() {

  // Only create if the login_history view doesn't exist and views is enabled.
  if (\Drupal::moduleHandler()
    ->moduleExists('views') && !View::load('login_history')) {
    $config_path = drupal_get_path('module', 'login_history') . '/config/install/views.view.login_history.yml';
    $data = Yaml::parseFile($config_path);
    \Drupal::configFactory()
      ->getEditable('views.view.login_history')
      ->setData($data)
      ->save(TRUE);
    return 'The new login_history view has been created.';
  }
  else {
    return 'Not creating a login_history view since it already exists.';
  }
}