Skip to content

Instantly share code, notes, and snippets.

@mohit-rocks
Forked from crittermike/import.php
Created December 4, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohit-rocks/73c1cf31a2426cb723723994fe45da30 to your computer and use it in GitHub Desktop.
Save mohit-rocks/73c1cf31a2426cb723723994fe45da30 to your computer and use it in GitHub Desktop.
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');
// Or, import YAML config an arbitrary directory.
$config_path = drupal_get_path('module', 'my_custom_module') . '/config/install';
$source = new FileStorage($config_path);
$config_storage = \Drupal::service('config.storage');
$config_storage->write('filter.format.basic_html', $source->read('filter.format.basic_html'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment