Chris@0: configObjects; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets the name of the extension that is being installed. Chris@0: * Chris@0: * @return string Chris@0: * The name of the extension that is being installed. Chris@0: */ Chris@0: public function getExtension() { Chris@0: return $this->extension; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Creates an exception for an extension and a list of configuration objects. Chris@0: * Chris@0: * @param $extension Chris@0: * The name of the extension that is being installed. Chris@0: * @param array $config_objects Chris@0: * A list of configuration objects that already exist in active Chris@0: * configuration, keyed by config collection. Chris@0: * Chris@0: * @return \Drupal\Core\Config\PreExistingConfigException Chris@0: */ Chris@0: public static function create($extension, array $config_objects) { Chris@17: $message = new FormattableMarkup('Configuration objects (@config_names) provided by @extension already exist in active configuration', Chris@0: [ Chris@0: '@config_names' => implode(', ', static::flattenConfigObjects($config_objects)), Chris@17: '@extension' => $extension, Chris@0: ] Chris@0: ); Chris@0: $e = new static($message); Chris@0: $e->configObjects = $config_objects; Chris@0: $e->extension = $extension; Chris@0: return $e; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Flattens the config object array to a single dimensional list. Chris@0: * Chris@0: * @param array $config_objects Chris@0: * A list of configuration objects that already exist in active Chris@0: * configuration, keyed by config collection. Chris@0: * Chris@0: * @return array Chris@0: * A list of configuration objects that have been prefixed with their Chris@0: * collection. Chris@0: */ Chris@0: public static function flattenConfigObjects(array $config_objects) { Chris@0: $flat_config_objects = []; Chris@0: foreach ($config_objects as $collection => $config_names) { Chris@0: $config_names = array_map(function ($config_name) use ($collection) { Chris@0: if ($collection != StorageInterface::DEFAULT_COLLECTION) { Chris@0: $config_name = str_replace('.', DIRECTORY_SEPARATOR, $collection) . DIRECTORY_SEPARATOR . $config_name; Chris@0: } Chris@0: return $config_name; Chris@0: }, $config_names); Chris@0: $flat_config_objects = array_merge($flat_config_objects, $config_names); Chris@0: } Chris@0: return $flat_config_objects; Chris@0: } Chris@0: Chris@0: }