diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 6ec8a5c..d1240fe 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -11,6 +11,7 @@ use Drupal\Core\Cache\Cache; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Yaml\Yaml; /** * Defines the configuration object factory. @@ -383,6 +384,18 @@ public function addOverride(ConfigFactoryOverrideInterface $config_factory_overr } /** + * {@inheritdoc} + */ + public function importNewConfig($name, $path, $trusted_data = FALSE) { + $config = $this->getEditable($name); + if (!$config->isNew()) { + throw new ConfigExistsException('The config ' . $name . ' already exists and can not be re-imported.'); + } + $data = Yaml::parse($path); + $config->setData($data)->save($trusted_data); + } + + /** * Creates a configuration object. * * @param string $name diff --git a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php index 69455a8..b8608a0 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php +++ b/core/lib/Drupal/Core/Config/ConfigFactoryInterface.php @@ -122,4 +122,20 @@ public function listAll($prefix = ''); */ public function addOverride(ConfigFactoryOverrideInterface $config_factory_override); + /** + * Import new configuration from a given path. + * + * @param string $name + * The config name to import. + * @param string $path + * Path to the configuration to import or YAML string. + * @param bool $trusted_data + * Set to TRUE if the configuration data has already been checked to ensure + * it conforms to schema. Generally this is only used during module and + * theme installation. + * + * @throws \Drupal\Core\Config\ConfigExistsException + */ + public function importNewConfig($name, $path); + }