Import a single config file in Drupal 8

Geschreven op 09 november 2018 door Jordi Fuite

Drupal's configuration management is one of the most important features in Drupal 8. During module development, configuration files can be placed in the config folder of the module. These will be imported during the installation of the module.

However, it may happen that you want to import a config file after installing the module. When you place a file in the config folder, it won't be imported by Drupal. In order to still being able to import the file, you can place the following snippet in your hook_update_N(). This way we have all configuration files in one folder and we’re all happy developers!

Want to know more about Drupal or the Your Source Team? Let us know by hitting the Contact button!

use Drupal\Core\Config\FileStorage;

// Enter the module name.
$module = 'ys_core';

// Enter the name of your config file (without the yml extension).
$config_file = 'uc_payment.method.rabo_omnikassa';

$config_path = drupal_get_path('module', $module) . '/config/install';
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('');
$config_storage->write($config_file, $source->read($config_file));

Reactie toevoegen

Plaats hier uw naam.