Provide helper method to import new config for already installed modules

Created on 12 August 2015, almost 10 years ago
Updated 27 May 2025, 4 days ago

Problem/Motivation

Modules should not update configuration once it has been installed because they could wipe out a site's customizations. However, when new configuration is added to a module (such as a View), then a quick helper method to read the new config and write it to the system would be quite helpful.

This is the current approach (from #2549675: Upgrade path for 2375589 β†’ ):

  // Only create if the view doesn't exist and views is enabled.
  if (!View::load('block_content') && \Drupal::moduleHandler()->moduleExists('views')) {
    $config_path = drupal_get_path('module', 'block_content') . '/config/optional/views.view.block_content.yml';
    $data = Yaml::parse($config_path);
    \Drupal::configFactory()->getEditable('views.view.block_content')->setData($data)->save(TRUE);
  }
  else {
    drupal_set_message('Not creating views.view.block_content since it already exists.');
  }

Proposed resolution

Add a method to ConfigFactory (or elsewhere?) that takes a path to configuration as the parameter. The method will throw an exception if the config already exists in the system.

Remaining tasks

User interface changes

API changes

New method on ConfigFactoryInterface.

Data model changes

πŸ“Œ Task
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

configuration system

Created by

πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for creating this issue to improve Drupal.

    We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024