You are here

config_rewrite.module in Configuration Rewrite 8

Allows modules to rewrite configuration provided by other extensions.

File

config_rewrite.module
View source
<?php

/**
 * @file
 * Allows modules to rewrite configuration provided by other extensions.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_module_preinstall().
 *
 * Allow config to be rewritten before a module is installed.
 */
function config_rewrite_module_preinstall($module) {
  global $install_state;

  // Rewrite config only the site is not being installed from configuration.
  if (empty($install_state['config_install_path'])) {
    \Drupal::service('config_rewrite.config_rewriter')
      ->rewriteModuleConfig($module);
  }
}

/**
 * Implements hook_help().
 */
function config_rewrite_help($route_name, RouteMatchInterface $arg) {
  switch ($route_name) {
    case 'help.page.config_rewrite':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The Configuration Rewrite module rewrites existing configuration on module installation via using a "rewrite" folder
in the config directory. Stops with an error, if you are going to rewrite config without having the original config in your database.

This can be handy, if you like to rewrite existing configuration (like admin user email address) without the need to
use install or update hooks. You can just place your configuration YAML files into the config/rewrite directory in your
module folder. Afterwards the existing configuration will be rewritten on module installation. For more information, see the project page for <a href=":documentation" target="_blank" title="Online Documentation">Configuration Rewrite</a>.', [
        ':documentation' => 'https://www.drupal.org/project/config_rewrite',
      ]) . '</p>';
      return $output;
  }
}