You are here

function redirect_update_8103 in Redirect 8

Creates the new default redirect view.

File

./redirect.install, line 142
Update hooks for the Redirect module.

Code

function redirect_update_8103() {
  $message = NULL;

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